Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 50 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import fs from 'fs'; |
||
2 | import path from 'path'; |
||
3 | import critical from '../../index'; |
||
4 | import { CriticalPluginConfig } from '../../@types/rollup-plugin-critical'; |
||
5 | import { Plugin } from 'rollup'; |
||
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', done => { |
||
26 | function callback(err: string) { |
||
27 | try { |
||
28 | expect(fs.readFileSync(testOutputPath)) |
||
29 | .toEqual(fs.readFileSync(expectedOutputPath)); |
||
30 | done(); |
||
31 | } catch (error) { |
||
32 | done(error); |
||
33 | } |
||
34 | } |
||
35 | // Instantiate the Rollup plugin |
||
36 | const plugin: Plugin = critical(pluginConfig, callback); |
||
37 | // Call the plugin to generate critical css |
||
38 | if (plugin && plugin.writeBundle) { |
||
39 | // @ts-ignore |
||
40 | const result = plugin.writeBundle({ |
||
41 | dir: testRoot, |
||
42 | }, { |
||
43 | chunk: { |
||
44 | type: 'asset', |
||
45 | fileName: 'style.css', |
||
46 | } |
||
47 | }); |
||
48 | } |
||
49 | }); |
||
50 |