|
1 | | -test.todo('support chaining with other loaders') |
| 1 | +import { SourceMapConsumer } from 'source-map' |
| 2 | +import { fs as mfs } from 'memfs' |
| 3 | +import { bundle, mockBundleAndRun } from './utils' |
2 | 4 |
|
3 | | -test.todo('inherit queries on files') |
| 5 | +test('support chaining with other loaders', async () => { |
| 6 | + const { componentModule } = await mockBundleAndRun({ |
| 7 | + entry: 'basic.vue', |
| 8 | + modify: (config) => { |
| 9 | + config!.module!.rules[0] = { |
| 10 | + test: /\.vue$/, |
| 11 | + use: ['vue-loader', require.resolve('./mock-loaders/js')], |
| 12 | + } |
| 13 | + }, |
| 14 | + }) |
4 | 15 |
|
5 | | -test.todo('expose file path as __file outside production') |
| 16 | + expect(componentModule.data().msg).toBe('Changed!') |
| 17 | +}) |
6 | 18 |
|
7 | | -test.todo('no __file in production when exposeFilename disabled') |
| 19 | +test.skip('inherit queries on files', async () => { |
| 20 | + const { componentModule } = await mockBundleAndRun({ |
| 21 | + entry: 'basic.vue?change', |
| 22 | + modify: (config) => { |
| 23 | + config!.module!.rules[0] = { |
| 24 | + test: /\.vue$/, |
| 25 | + use: ['vue-loader', require.resolve('./mock-loaders/query')], |
| 26 | + } |
| 27 | + }, |
| 28 | + }) |
8 | 29 |
|
9 | | -test.todo( |
10 | | - 'expose file basename as __file in production when exposeFilename enabled' |
11 | | -) |
| 30 | + expect(componentModule.data().msg).toBe('Changed!') |
| 31 | +}) |
12 | 32 |
|
13 | | -test.todo('source map') |
| 33 | +test('expose file path as __file outside production', async () => { |
| 34 | + const { componentModule } = await mockBundleAndRun({ |
| 35 | + entry: 'basic.vue', |
| 36 | + }) |
| 37 | + |
| 38 | + expect(componentModule.__file).toBe('test/fixtures/basic.vue') |
| 39 | +}) |
| 40 | + |
| 41 | +test('no __file in production when exposeFilename disabled', async () => { |
| 42 | + const { componentModule } = await mockBundleAndRun({ |
| 43 | + mode: 'production', |
| 44 | + entry: 'basic.vue', |
| 45 | + }) |
| 46 | + |
| 47 | + expect(componentModule.__file).toBe(undefined) |
| 48 | +}) |
| 49 | + |
| 50 | +test('expose file basename as __file in production when exposeFilename enabled', async () => { |
| 51 | + const { componentModule } = await mockBundleAndRun({ |
| 52 | + mode: 'production', |
| 53 | + entry: 'basic.vue', |
| 54 | + vue: { |
| 55 | + exposeFilename: true, |
| 56 | + }, |
| 57 | + }) |
| 58 | + expect(componentModule.__file).toBe('basic.vue') |
| 59 | +}) |
| 60 | + |
| 61 | +test.skip('source map', async () => { |
| 62 | + const { code } = await bundle({ |
| 63 | + entry: 'basic.vue', |
| 64 | + devtool: 'source-map', |
| 65 | + }) |
| 66 | + const map = mfs.readFileSync('/test.build.js.map', 'utf-8') |
| 67 | + const smc = new SourceMapConsumer(JSON.parse(map as string)) |
| 68 | + let line = 0 |
| 69 | + let col = 0 |
| 70 | + const targetRE = /^\s+msg: 'Hello from Component A!'/ |
| 71 | + code.split(/\r?\n/g).some((l, i) => { |
| 72 | + if (targetRE.test(l)) { |
| 73 | + line = i + 1 |
| 74 | + col = 0 |
| 75 | + return true |
| 76 | + } |
| 77 | + }) |
| 78 | + const pos = smc.originalPositionFor({ |
| 79 | + line: line, |
| 80 | + column: col, |
| 81 | + }) |
| 82 | + expect(pos.source.indexOf('basic.vue') > -1) |
| 83 | + expect(pos.line).toBe(9) |
| 84 | +}) |
14 | 85 |
|
15 | 86 | test.todo('extract CSS') |
16 | 87 |
|
|
0 commit comments