Test Failed
Branch develop (785de4)
by Andrew
02:36
created

src/__tests__/index.test.ts   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 44
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.test.ts ➔ callback 0 7 2
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