-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-duplicated-vue-import.spec.ts
80 lines (72 loc) · 2.24 KB
/
no-duplicated-vue-import.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
import { ConfigSet } from "ts-jest/dist/config/config-set";
import tsc from "typescript";
import * as removeVueImport from "../src/transformers/no-duplicated-vue-import";
const CODE_WITH_VUE_IMPORT = `
import { defineComponent, ref } from 'vue'
const vue_1 = require('vue')
import * as vue1 from 'vue'
const vue2 = require('vue')
import vue3 = require('vue')
export default defineComponent({
setup() {
const count = ref<string>(5)
const inc = () => count.value++
const vue4 = require('vue')
vue1.foo(1)
vue2.foo(2)
vue3.foo(3)
vue4.foo(4)
vue_1.foo(5)
return {
count,
inc
}
}
})
`;
describe("remove-vue-import", () => {
test('should have correct signature', () => {
expect(removeVueImport.name).toBe('no-duplicated-vue-import')
expect(typeof removeVueImport.version).toBe('number')
expect(removeVueImport.version).toBeGreaterThan(0)
expect(typeof removeVueImport.factory).toBe('function')
})
test('should remove duplicated global vue import', () => {
const configSet = new ConfigSet(Object.create(null));
const createFactory = () => removeVueImport.factory(configSet);
const transpile = (source: string) =>
tsc.transpileModule(source, {
transformers: { after: [createFactory()] },
});
const out = transpile(CODE_WITH_VUE_IMPORT);
expect(out).toMatchInlineSnapshot(`
Object {
"diagnostics": Array [],
"outputText": "\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
var vue_1 = require('vue');
var vue1 = require(\\"vue\\");
var vue2 = require('vue');
var vue3 = require(\\"vue\\");
exports.default = vue_2.defineComponent({
setup: function () {
var count = vue_2.ref(5);
var inc = function () { return count.value++; };
var vue4 = require('vue');
vue1.foo(1);
vue2.foo(2);
vue3.foo(3);
vue4.foo(4);
vue_1.foo(5);
return {
count: count,
inc: inc
};
}
});
",
"sourceMapText": undefined,
}
`);
});
});