|
| 1 | +jest.setTimeout(40000) |
| 2 | + |
| 3 | +const { defaultPreset } = require('@vue/cli/lib/options') |
| 4 | +const create = require('@vue/cli-test-utils/createTestProject') |
| 5 | + |
| 6 | +let project |
| 7 | + |
| 8 | +beforeAll(async () => { |
| 9 | + project = await create('build-lib-formats', defaultPreset) |
| 10 | +}) |
| 11 | + |
| 12 | +test('build as lib with default formats', async () => { |
| 13 | + const { stdout } = await project.run('vue-cli-service build --target lib --name testLib src/components/HelloWorld.vue') |
| 14 | + expect(stdout).toMatch('Build complete.') |
| 15 | + |
| 16 | + expect(project.has('dist/demo.html')).toBe(true) |
| 17 | + expect(project.has('dist/testLib.common.js')).toBe(true) |
| 18 | + expect(project.has('dist/testLib.umd.js')).toBe(true) |
| 19 | + expect(project.has('dist/testLib.umd.min.js')).toBe(true) |
| 20 | + expect(project.has('dist/testLib.css')).toBe(true) |
| 21 | +}) |
| 22 | +test('build as lib with formats commonjs and umd', async () => { |
| 23 | + const { stdout } = await project.run('vue-cli-service build --target lib --formats commonjs,umd --name testLib src/components/HelloWorld.vue') |
| 24 | + expect(stdout).toMatch('Build complete.') |
| 25 | + |
| 26 | + expect(project.has('dist/demo.html')).toBe(true) |
| 27 | + expect(project.has('dist/testLib.common.js')).toBe(true) |
| 28 | + expect(project.has('dist/testLib.umd.js')).toBe(true) |
| 29 | + expect(project.has('dist/testLib.umd.min.js')).toBe(false) |
| 30 | + expect(project.has('dist/testLib.css')).toBe(true) |
| 31 | +}) |
| 32 | + |
| 33 | +test('build as lib with format umd-min', async () => { |
| 34 | + const { stdout } = await project.run('vue-cli-service build --target lib --formats umd-min --name testLib src/components/HelloWorld.vue') |
| 35 | + expect(stdout).toMatch('Build complete.') |
| 36 | + |
| 37 | + expect(project.has('dist/demo.html')).toBe(false) |
| 38 | + expect(project.has('dist/testLib.common.js')).toBe(false) |
| 39 | + expect(project.has('dist/testLib.umd.js')).toBe(false) |
| 40 | + expect(project.has('dist/testLib.umd.min.js')).toBe(true) |
| 41 | + expect(project.has('dist/testLib.css')).toBe(true) |
| 42 | +}) |
| 43 | + |
| 44 | +test('build as lib with unknown formats throws an error', async () => { |
| 45 | + try { |
| 46 | + await project.run('vue-cli-service build --target lib --formats umd,x,y --name testLib src/components/HelloWorld.vue') |
| 47 | + } catch (e) { |
| 48 | + expect(e.code).toBe(1) |
| 49 | + expect(e.failed).toBeTruthy() |
| 50 | + } |
| 51 | +}) |
0 commit comments