Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 44 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Plugin} from 'rollup'; |
||
2 | import critical from '../index'; |
||
3 | import fs from 'fs'; |
||
4 | import path from 'path'; |
||
5 | |||
6 | const TESTS_ROOT = './src/__tests__/'; |
||
7 | |||
8 | test('Basic Critical CSS generation', done => { |
||
9 | function callback(err: string) { |
||
10 | try { |
||
11 | expect(fs.readFileSync(path.join(TESTS_ROOT, 'test_critical.min.css'))) |
||
12 | .toEqual(fs.readFileSync(path.join(TESTS_ROOT, 'index_critical.min.css'))); |
||
13 | done(); |
||
14 | } catch (error) { |
||
15 | done(error); |
||
16 | } |
||
17 | } |
||
18 | // Instantiate the Rollup plugin |
||
19 | const plugin: Plugin = critical({ |
||
20 | criticalBase: TESTS_ROOT, |
||
21 | criticalUrl: TESTS_ROOT, |
||
22 | pages: [ |
||
23 | { |
||
24 | uri: 'index.html', |
||
25 | template: 'test', |
||
26 | } |
||
27 | ], |
||
28 | criticalConfig: { |
||
29 | } |
||
30 | }, callback); |
||
31 | // Call the plugin to generate critical css |
||
32 | if (plugin && plugin.writeBundle) { |
||
33 | // @ts-ignore |
||
34 | const result = plugin.writeBundle({ |
||
35 | dir: TESTS_ROOT, |
||
36 | }, { |
||
37 | chunk: { |
||
38 | type: 'asset', |
||
39 | fileName: 'style.css', |
||
40 | } |
||
41 | }); |
||
42 | } |
||
43 | }); |
||
44 |