Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 43 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import fs from 'fs'; |
||
2 | import path from 'path'; |
||
3 | import {PluginCritical} from '../../index'; |
||
4 | import {Plugin} from 'rollup'; |
||
5 | import {expect, test} from 'vitest' |
||
6 | |||
7 | const testRoot = path.join(__dirname, '/'); |
||
8 | const testOutputPath = path.join(testRoot, '__output__/test_critical.min.css'); |
||
9 | |||
10 | const pluginConfig: CriticalPluginConfig = { |
||
11 | criticalBase: testRoot, |
||
12 | criticalUrl: testRoot, |
||
13 | criticalPages: [ |
||
14 | { |
||
15 | uri: 'index.html', |
||
16 | template: '__output__/test', |
||
17 | } |
||
18 | ], |
||
19 | criticalConfig: { |
||
20 | inline: false, |
||
21 | }, |
||
22 | }; |
||
23 | |||
24 | test('`inline: false` Critical CSS generation', async () => { |
||
25 | // Instantiate the Rollup plugin |
||
26 | const plugin: Plugin = PluginCritical(pluginConfig); |
||
27 | // Call the plugin to generate critical css |
||
28 | if (plugin && typeof plugin.writeBundle === 'function') { |
||
29 | // @ts-ignore |
||
30 | await plugin.writeBundle({ |
||
31 | dir: testRoot, |
||
32 | }, { |
||
33 | chunk: { |
||
34 | type: 'asset', |
||
35 | fileName: 'style.css', |
||
36 | } |
||
37 | }); |
||
38 | // Compare the output with the snapshot |
||
39 | expect(fs.readFileSync(testOutputPath).toString()) |
||
40 | .toMatchSnapshot(); |
||
41 | } |
||
42 | }); |
||
43 |