Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 45 |
Function Count | 1 |
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, 'test_critical.min.css'); |
||
9 | const expectedOutputPath = path.join(testRoot, 'index_critical.min.css'); |
||
10 | |||
11 | const pluginConfig: CriticalPluginConfig = { |
||
12 | criticalBase: testRoot, |
||
13 | criticalUrl: testRoot, |
||
14 | criticalPages: [ |
||
15 | { |
||
16 | uri: 'index.html', |
||
17 | template: 'test', |
||
18 | } |
||
19 | ], |
||
20 | criticalConfig: { |
||
21 | inline: false, |
||
22 | }, |
||
23 | }; |
||
24 | |||
25 | test('`inline: false` Critical CSS generation', () => { |
||
26 | function callback() { |
||
27 | expect(fs.readFileSync(testOutputPath)) |
||
28 | .toEqual(fs.readFileSync(expectedOutputPath)); |
||
29 | } |
||
30 | // Instantiate the Rollup plugin |
||
31 | const plugin: Plugin = PluginCritical(pluginConfig, callback); |
||
32 | // Call the plugin to generate critical css |
||
33 | if (plugin && typeof plugin.writeBundle === 'function') { |
||
34 | // @ts-ignore |
||
35 | plugin.writeBundle({ |
||
36 | dir: testRoot, |
||
37 | }, { |
||
38 | chunk: { |
||
39 | type: 'asset', |
||
40 | fileName: 'style.css', |
||
41 | } |
||
42 | }); |
||
43 | } |
||
44 | }); |
||
45 |