Skip to content

Commit 50d32aa

Browse files
wip(tests): add more tests
1 parent 1dee313 commit 50d32aa

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

tests/basic.test.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,109 @@ test.only('nested mjs import', async () => {
220220
await page.close();
221221
});
222222

223+
224+
test('nested js require', async () => {
225+
226+
const { page, output } = await createPage({
227+
files: {
228+
...defaultFiles,
229+
'/component.vue': `
230+
<script>
231+
const { test } = require('./foo/test.js')
232+
console.log( test() );
233+
</script>
234+
`,
235+
236+
'/foo/test.js': `
237+
exports.test = function() {
238+
239+
return require('../bar/test.js').test();
240+
}
241+
`,
242+
243+
'/bar/test.js': `
244+
exports.test = function() {
245+
246+
return 'test_ok';
247+
}
248+
`
249+
}
250+
});
251+
252+
await expect(output.some(e => e.type === 'log' && e.content[0] === 'test_ok' )).toBe(true);
253+
254+
await page.close();
255+
});
256+
257+
258+
259+
test('access es6 module default from cjs', async () => {
260+
261+
const { page, output } = await createPage({
262+
files: {
263+
...defaultFiles,
264+
'/component.vue': `
265+
<script>
266+
const { test } = require('./foo/test.js')
267+
console.log( test() );
268+
</script>
269+
`,
270+
271+
'/foo/test.js': `
272+
exports.test = function() {
273+
274+
return require('../bar/test.mjs').default();
275+
}
276+
`,
277+
278+
'/bar/test.mjs': `
279+
export default function() {
280+
281+
return 'test_ok';
282+
}
283+
`
284+
}
285+
});
286+
287+
await expect(output.some(e => e.type === 'log' && e.content[0] === 'test_ok' )).toBe(true);
288+
289+
await page.close();
290+
});
291+
292+
293+
294+
test('access cjs module default from es6', async () => {
295+
296+
const { page, output } = await createPage({
297+
files: {
298+
...defaultFiles,
299+
'/component.vue': `
300+
<script>
301+
const { test } = require('./foo/test.mjs')
302+
console.log( test() );
303+
</script>
304+
`,
305+
306+
'/foo/test.mjs': `
307+
308+
import test1 from '../bar/test.js'
309+
export function test() {
310+
311+
return test1();
312+
}
313+
`,
314+
315+
'/bar/test.js': `
316+
module.exports = function() {
317+
318+
return 'test_ok';
319+
}
320+
`
321+
}
322+
});
323+
324+
await expect(output.some(e => e.type === 'log' && e.content[0] === 'test_ok' )).toBe(true);
325+
326+
await page.close();
327+
});
328+

0 commit comments

Comments
 (0)