/
build.spec.ts
88 lines (73 loc) · 3.04 KB
/
build.spec.ts
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
import { sass } from '../dist';
import { PluginCtx } from '../dist/declarations';
import * as fs from 'fs';
import * as path from 'path';
describe('test build', () => {
let context: PluginCtx;
beforeEach(() => {
context = {
config: {
rootDir: '/Users/my/app/',
srcDir: '/Users/my/app/src/',
},
cache: null,
sys: {} as any,
fs: {
readFileSync(filePath: string) {
return fs.readFileSync(filePath, 'utf8');
},
writeFile() {
return Promise.resolve();
}
} as any,
diagnostics: []
};
})
it('transform', async () => {
const filePath = path.join(__dirname, 'fixtures', 'test-a.scss');
const sourceText = fs.readFileSync(filePath, 'utf8');
const s = sass();
const results = await s.transform(sourceText, filePath, context) as any;
expect(results.code).toContain('color: red');
expect(results.diagnostics).toEqual(undefined);
});
it('transform, import', async () => {
const filePath = path.join(__dirname, 'fixtures', 'test-b.scss');
const sourceText = fs.readFileSync(filePath, 'utf8');
const s = sass();
const results = await s.transform(sourceText, filePath, context) as any;
expect(results.code).toContain('color: red');
expect(results.diagnostics).toEqual(undefined);
});
it('transform, error', async () => {
const filePath = path.join(__dirname, 'fixtures', 'test-c.scss');
const sourceText = fs.readFileSync(filePath, 'utf8');
const s = sass();
await s.transform(sourceText, filePath, context);
expect(context.diagnostics).toHaveLength(1);
expect(context.diagnostics[0].level).toEqual('error');
expect(context.diagnostics[0].language).toEqual('scss');
expect(context.diagnostics[0].lineNumber).toEqual(2);
expect(context.diagnostics[0].columnNumber).toEqual(23);
expect(context.diagnostics[0].lines.length).toEqual(3);
expect(context.diagnostics[0].lines[0].lineIndex).toEqual(0);
expect(context.diagnostics[0].lines[0].lineNumber).toEqual(1);
expect(context.diagnostics[0].lines[0].errorCharStart).toEqual(-1);
expect(context.diagnostics[0].lines[0].errorLength).toEqual(-1);
expect(context.diagnostics[0].lines[0].text).toEqual('body{color:blue}');
expect(context.diagnostics[0].lines[1].lineIndex).toEqual(1);
expect(context.diagnostics[0].lines[1].lineNumber).toEqual(2);
expect(context.diagnostics[0].lines[1].errorCharStart).toEqual(22);
expect(context.diagnostics[0].lines[1].errorLength).toEqual(1);
expect(context.diagnostics[0].lines[1].text).toEqual(' hello i am an error!');
expect(context.diagnostics[0].lines[2].lineIndex).toEqual(2);
expect(context.diagnostics[0].lines[2].lineNumber).toEqual(3);
expect(context.diagnostics[0].lines[2].errorCharStart).toEqual(-1);
expect(context.diagnostics[0].lines[2].errorLength).toEqual(-1);
expect(context.diagnostics[0].lines[2].text).toEqual(' div{color:green}');
});
it('name', async () => {
const s = sass();
expect(s.name).toBe('sass');
});
});