2021-08-10 00:27:23 +00:00
|
|
|
import { expect } from 'chai'
|
2021-10-11 08:07:27 +00:00
|
|
|
import { TransformPlugin } from '../src/auto-imports/transform'
|
2021-08-10 00:27:23 +00:00
|
|
|
|
2021-10-11 08:07:27 +00:00
|
|
|
describe('module:auto-imports:build', () => {
|
2021-08-30 11:55:57 +00:00
|
|
|
const { transform: _transform } = TransformPlugin.raw({ ref: 'vue', computed: 'bar' }, {} as any)
|
|
|
|
const transform = (code: string) => _transform.call({} as any, code, '')
|
2021-08-10 00:27:23 +00:00
|
|
|
|
2021-08-30 11:55:57 +00:00
|
|
|
it('should correct inject', async () => {
|
2021-10-12 12:24:43 +00:00
|
|
|
expect(await transform('const a = ref(0)')).to.equal('import { ref } from \'vue\';const a = ref(0)')
|
|
|
|
expect(await transform('import { computed as ref } from "foo"; const a = ref(0)')).to.includes('import { computed } from \'bar\';')
|
2021-08-10 00:27:23 +00:00
|
|
|
})
|
|
|
|
|
2021-10-12 12:24:43 +00:00
|
|
|
it('should ignore existing imported', async () => {
|
|
|
|
expect(await transform('import { ref } from "foo"; const a = ref(0)')).to.equal(null)
|
|
|
|
expect(await transform('import ref from "foo"; const a = ref(0)')).to.equal(null)
|
|
|
|
expect(await transform('import { z as ref } from "foo"; const a = ref(0)')).to.equal(null)
|
|
|
|
expect(await transform('let ref = () => {}; const a = ref(0)')).to.equal(null)
|
|
|
|
expect(await transform('let { ref } = Vue; const a = ref(0)')).to.equal(null)
|
|
|
|
expect(await transform('let [\ncomputed,\nref\n] = Vue; const a = ref(0); const b = ref(0)')).to.equal(null)
|
2021-08-30 11:55:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should ignore comments', async () => {
|
|
|
|
const result = await transform('// import { computed } from "foo"\n;const a = computed(0)')
|
|
|
|
expect(result).to.equal('import { computed } from \'bar\';// import { computed } from "foo"\n;const a = computed(0)')
|
2021-08-10 00:27:23 +00:00
|
|
|
})
|
|
|
|
})
|