-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathscss.test.ts
78 lines (60 loc) · 2.29 KB
/
scss.test.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
/* eslint-disable node/global-require */
/* eslint-disable @typescript-eslint/no-require-imports */
import { resolve } from 'path';
import { describe, it, expect } from 'vitest';
import { sveltePreprocess } from '../../src';
import { preprocess } from '../utils';
import { transformer } from '../../src/transformers/scss';
describe('transformer - scss', () => {
it('should return @imported files as dependencies - via default async render', async () => {
const template = `<style lang="scss">@import "./fixtures/style.scss";</style>`;
const opts = sveltePreprocess();
const preprocessed = await preprocess(template, opts);
expect(preprocessed.dependencies).toContain(
resolve(__dirname, '..', 'fixtures', 'style.scss'),
);
});
it('should return @imported files as dependencies - via renderSync', async () => {
const template = `<style lang="scss">@import "fixtures/style.scss";</style>`;
const opts = sveltePreprocess({});
const preprocessed = await preprocess(template, opts);
expect(preprocessed.dependencies).toContain(
resolve(__dirname, '..', 'fixtures', 'style.scss'),
);
});
it('should prepend scss content via `data` option property - via renderSync', async () => {
const template = `<style lang="scss"></style>`;
const opts = sveltePreprocess({
scss: {
prependData: '$color:blue;div{color:$color}',
},
});
const preprocessed = await preprocess(template, opts);
expect(preprocessed.toString?.()).toContain('blue');
});
it('supports ~ tilde imports (removes the character)', async () => {
const template = `<style lang="scss">@import '~scss-package/main.scss'</style>`;
const opts = sveltePreprocess();
const preprocessed = await preprocess(template, opts);
expect(preprocessed.toString?.()).toMatchInlineSnapshot(`
"<style lang="scss">div {
color: pink;
}</style>"
`);
});
it('returns the source map and removes sourceMappingURL from code', async () => {
const content = `
$color:red;
div{
color:$color
}
`;
const filename = '/file';
const options = {
sourceMap: true,
};
const { map, code } = await transformer({ content, filename, options });
expect(code).not.toContain('sourceMappingURL');
expect(map).toBeDefined();
});
});