Passed
Push — master ( 57915b...d0caeb )
by Andrew
10:09 queued 06:26
created

src/__tests__/inline-true/index.test.ts   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 50
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 39
mnd 2
bc 2
fnc 1
dl 0
loc 50
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.test.ts ➔ callback 0 7 2
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_index.html');
9
const expectedOutputPath = path.join(testRoot, 'index_critical.html');
10
11
const pluginConfig: CriticalPluginConfig = {
12
    criticalBase: testRoot,
13
    criticalUrl: testRoot,
14
    criticalPages: [
15
        {
16
            uri: 'index.html',
17
            template: 'test_index',
18
        }
19
    ],
20
    criticalConfig: {
21
        inline: true,
22
    },
23
};
24
25
test('`inline: true` 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