forked from Netcentric/fe-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderPostcss.test.js
More file actions
80 lines (71 loc) · 3.01 KB
/
renderPostcss.test.js
File metadata and controls
80 lines (71 loc) · 3.01 KB
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
const fs = require('fs');
const path = require('path');
const defaults = require('../config');
const extendConfig = require('../utils/extendConfig');
const renderPostcss = require('./renderPostcss');
// prevent logs from extend config
console.log = jest.fn();
const config = extendConfig('./test/.febuild', defaults);
const outFile = path.resolve(`./test/dist/postcss/component.dist.css`);
const inputContent = {css: `::placeholder {
color: gray;
}
.image {
background-image: url(image@1x.png);
}
@media (min-resolution: 2dppx) {
.image {
background-image: url(image@2x.png);
}
}`};
const outputContent = '::-moz-placeholder {\n' +
' color: gray;\n' +
'}\n' +
'\n' +
'::placeholder {\n' +
' color: gray;\n' +
'}\n' +
'\n' +
'.image {\n' +
' background-image: url(image@1x.png);\n' +
'}\n' +
'\n' +
'@media (min-resolution: 2dppx) {\n' +
' .image {\n' +
' background-image: url(image@2x.png);\n' +
' }\n' +
'}';
sourceMapOutput = `
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvZGlzdC9wb3N0Y3NzL2NvbXBvbmVudC5kaXN0LmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtJQUNJLFdBQVc7QUFDZjs7QUFGQTtJQUNJLFdBQVc7QUFDZjs7QUFFQTtJQUNJLG1DQUFtQztBQUN2Qzs7QUFFQTtJQUNJO1FBQ0ksbUNBQW1DO0lBQ3ZDO0FBQ0oiLCJmaWxlIjoidGVzdC9kaXN0L3Bvc3Rjc3MvY29tcG9uZW50LmRpc3QuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiOjpwbGFjZWhvbGRlciB7XG4gICAgY29sb3I6IGdyYXk7XG59XG5cbi5pbWFnZSB7XG4gICAgYmFja2dyb3VuZC1pbWFnZTogdXJsKGltYWdlQDF4LnBuZyk7XG59XG5cbkBtZWRpYSAobWluLXJlc29sdXRpb246IDJkcHB4KSB7XG4gICAgLmltYWdlIHtcbiAgICAgICAgYmFja2dyb3VuZC1pbWFnZTogdXJsKGltYWdlQDJ4LnBuZyk7XG4gICAgfVxufSJdfQ== */`;
describe('Test utils/renderPostcss.js', () => {
it(`Postcss render autoprefix plugin`, async () => {
config.postcss.failOnError = false;
console.log = jest.fn();
await renderPostcss(inputContent, outFile, config, (r) => {
expect(r.css).toBe(outputContent);
});
});
it(`Postcss render autoprefix plugin with source maps`, async () => {
config.postcss.failOnError = false;
config.general.isProduction = false;
console.log = jest.fn();
await renderPostcss({...inputContent, map:''}, outFile, config, (r) => {
expect(r.css).toBe(outputContent + sourceMapOutput);
});
// return config
config.general.isProduction = true;
});
it(`Postcss should return errors by loggin when failOnError is false`, async () => {
config.postcss.failOnError = false;
console.error = jest.fn();
console.log = jest.fn();
await renderPostcss('s', 's', config, (r) =>r);
expect((console.error.mock.calls[0] || console.log.mock.calls[0]).length).toBeGreaterThan(0);
});
it(`Should Should exit 1 with erros failOnError`, async () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {});
config.postcss.failOnError = true;
await renderPostcss(false, false, config);
expect(mockExit).toHaveBeenCalledWith(1);
});
})