Test Failed
Push — master ( d295c6...601e9b )
by Andrew
06:35 queued 03:09
created

src/__tests__/inline-false/inline-false.test.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 43
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 33
mnd 1
bc 1
fnc 0
dl 0
loc 43
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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