-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
111 lines (101 loc) · 2.96 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
const test = require('tape');
const Vinyl = require('vinyl');
const streamArray = require('stream-array');
const streamAssert = require('stream-assert');
const cssModule = require('./index');
const path = require('path');
const { Readable } = require('stream');
const cwd = process.cwd();
test('cssModule does not support streaming', t => {
const a = new Vinyl({
cwd,
base: path.join(cwd, 'src'),
path: path.join(cwd, 'src', 'app.js'),
contents: new Readable({})
});
streamArray([a])
.pipe(cssModule())
.once('error', function (err) {
t.equal(err.message, 'Streaming is not supported');
t.end();
});
});
test('gulp-dumber-css-modules ignores non-css file', t => {
const a = new Vinyl({
cwd,
base: path.join(cwd, 'src'),
path: path.join(cwd, 'src', 'app.js'),
contents: Buffer.from("lorem")
});
streamArray([a])
.pipe(cssModule())
.once('error', function (err) {
t.fail(err.message);
t.end();
})
.pipe(streamAssert.length(1))
.pipe(streamAssert.first(f => {
t.equal(f.path, a.path);
t.equal(f.contents.toString(), a.contents.toString());
t.notOk(f.sourceMap);
}))
.pipe(streamAssert.end(t.end));
});
test('gulp-dumber-css-modules transforms css file', t => {
const a = new Vinyl({
cwd,
base: path.join(cwd, 'src'),
path: path.join(cwd, 'src', 'app.css'),
contents: Buffer.from(".a { color: red; }")
});
streamArray([a])
.pipe(cssModule())
.once('error', function (err) {
t.fail(err.message);
t.end();
})
.pipe(streamAssert.length(1))
.pipe(streamAssert.first(f => {
t.equal(f.path, a.path);
const contents = f.contents.toString();
const m = contents.match(/^\.(\S+) { color: red; }\n\/\* dumber-css-module: {"a":"\1"} \*\/\n$/);
t.ok(m);
t.notOk(f.sourceMap);
}))
.pipe(streamAssert.end(t.end));
});
test('gulp-dumber-css-modules transforms css file with sourceMap', t => {
const a = new Vinyl({
cwd,
base: path.join(cwd, 'src'),
path: path.join(cwd, 'src', 'app.css'),
contents: Buffer.from(".a { color: red; }"),
});
a.sourceMap = {
version: 3,
file: 'app.css',
sources: ['app.scss'],
mappings: 'AAAA',
sourcesContent: [".a { color: red; }"]
};
streamArray([a])
.pipe(cssModule())
.once('error', function (err) {
t.fail(err.message);
t.end();
})
.pipe(streamAssert.length(1))
.pipe(streamAssert.first(f => {
t.equal(f.path, a.path);
const contents = f.contents.toString();
const m = contents.match(/^\.(\S+) { color: red; }\n\/\* dumber-css-module: {"a":"\1"} \*\/\n$/);
t.ok(m);
t.ok(f.sourceMap);
t.equal(f.sourceMap.file, 'app.css');
t.equal(f.sourceMap.mappings, 'AAAA,cAAA,UAAA,EAAA');
t.deepEqual(f.sourceMap.sourcesContent, [".a { color: red; }"]);
t.deepEqual(f.sourceMap.sources, ['app.scss']);
}))
.pipe(streamAssert.end(t.end));
});