forked from getyourguide/vue-class-migrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrator-to-sfc.test.ts
37 lines (33 loc) · 1.32 KB
/
migrator-to-sfc.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
import { project, createSourceFile } from './utils';
import { vueFileToSFC } from '../migrator/migrator-to-sfc';
describe('vueFileToSFC()', () => {
afterAll(() => {
project.getSourceFiles().forEach((file) => file.deleteImmediatelySync());
});
test('Style without src is copied', async () => {
const body = '<style>body {}</style>';
const sourceFile = createSourceFile(body);
const result = await vueFileToSFC(project, sourceFile);
await expect(result.getText()).toBe(body);
});
test('Scoped style is transformed', async () => {
const css = 'body {}';
const cssSourceFile = createSourceFile(css, 'scss');
const body = `<style scoped src="${cssSourceFile.getFilePath()}" />`;
const sourceFile = createSourceFile(body);
const result = await vueFileToSFC(project, sourceFile);
await expect(result.getText()).toBe(
`<style lang="scss" scoped>\n${css}\n</style>`,
);
});
test('Non-scoped style is transformed', async () => {
const css = 'body {}';
const cssSourceFile = createSourceFile(css, 'scss');
const body = `<style src="${cssSourceFile.getFilePath()}" />`;
const sourceFile = createSourceFile(body);
const result = await vueFileToSFC(project, sourceFile);
await expect(result.getText()).toBe(
`<style lang="scss">\n${css}\n</style>`,
);
});
});