-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
executable file
·90 lines (83 loc) · 2.55 KB
/
index.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
const expect = require('expect.js');
const fs = require('fs');
const path = require('path');
const runWebpack = require('./helpers/run-webpack');
describe('optimize cssnano plugin', () => {
it('should update original source map', () => {
const paths = getCasePaths('map-map');
try {
fs.unlinkSync(paths['produced-css']);
} catch (e) {
// noop
}
try {
fs.unlinkSync(paths['produced-map']);
} catch (e) {
// noop
}
return runWebpack(paths.source).then((result) => {
// expect(fs.readFileSync(paths['produced-css']).toString())
// .to.eql(fs.readFileSync(paths['expected-css']).toString());
expect(fs.readFileSync(paths['produced-map']).toString())
.to.eql(fs.readFileSync(paths['expected-map']).toString());
});
});
it('should remove original source map', () => {
const paths = getCasePaths('map-nomap');
try {
fs.unlinkSync(paths['produced-css']);
} catch (e) {
// noop
}
try {
fs.unlinkSync(paths['produced-map']);
} catch (e) {
// noop
}
return runWebpack(paths.source, true, false).then((result) => {
// expect(fs.readFileSync(paths['produced-css']).toString())
// .to.eql(fs.readFileSync(paths['expected-css']).toString());
expect(fs.existsSync(paths['produced-map']))
.to.be(false);
});
});
it('should generate new source map', () => {
const paths = getCasePaths('nomap-map');
try {
fs.unlinkSync(paths['produced-css']);
} catch (e) {
// noop
}
try {
fs.unlinkSync(paths['produced-map']);
} catch (e) {
// noop
}
return runWebpack(paths.source, false, true).then((result) => {
// expect(fs.readFileSync(paths['produced-css']).toString())
// .to.eql(fs.readFileSync(paths['expected-css']).toString());
expect(fs.readFileSync(paths['produced-map']).toString())
.to.eql(fs.readFileSync(paths['expected-map']).toString());
});
});
});
/**
* Generate paths to source and expected files
*
* @param {String} caseName
* @return {{source: *, expected: *}}
*/
function getCasePaths(caseName) {
return {
'source': path.join(__dirname, 'cases', caseName,
'source.js'),
'expected-css': path.join(__dirname, 'cases', caseName,
'expected.css'),
'expected-map': path.join(__dirname, 'cases', caseName,
'expected.css.map'),
'produced-css': path.join(__dirname, 'cases', caseName,
'produced.css'),
'produced-map': path.join(__dirname, 'cases', caseName,
'produced.css.map'),
};
}