diff --git a/test/coverage-test/fixtures/src/cjs-package/entry.js b/test/coverage-test/fixtures/src/cjs-package/entry.js new file mode 100644 index 000000000000..883382e4e68e --- /dev/null +++ b/test/coverage-test/fixtures/src/cjs-package/entry.js @@ -0,0 +1,2 @@ +require("./target"); +module.exports = "Entry here" \ No newline at end of file diff --git a/test/coverage-test/fixtures/src/cjs-package/package.json b/test/coverage-test/fixtures/src/cjs-package/package.json new file mode 100644 index 000000000000..d7243077cec0 --- /dev/null +++ b/test/coverage-test/fixtures/src/cjs-package/package.json @@ -0,0 +1,5 @@ +{ + "name": "cjs-package", + "main": "./entry.js", + "type": "commonjs" +} \ No newline at end of file diff --git a/test/coverage-test/fixtures/src/cjs-package/target.js b/test/coverage-test/fixtures/src/cjs-package/target.js new file mode 100644 index 000000000000..8a5e164e4564 --- /dev/null +++ b/test/coverage-test/fixtures/src/cjs-package/target.js @@ -0,0 +1,9 @@ +"use strict"; + +module.exports = { + debug: 0, + info: 1, + warn: 2, + error: 3, + fatal: 4, +}; diff --git a/test/coverage-test/test/file-outside-vite.test.ts b/test/coverage-test/test/file-outside-vite.test.ts index 109cddfcc337..e6906d8c7f63 100644 --- a/test/coverage-test/test/file-outside-vite.test.ts +++ b/test/coverage-test/test/file-outside-vite.test.ts @@ -79,3 +79,17 @@ coverageTest('load file using require so it\'s not intercepted by Vite', () => { expect(noop).toBeTypeOf('function') }) + +coverageTest('load file both from Vite and outside it', async () => { + const entry = createRequire(import.meta.url)('../fixtures/src/cjs-package' as any) + const target = await import('../fixtures/src/cjs-package/target.js' as any) + + expect(entry).toBe('Entry here') + expect(target.default).toStrictEqual({ + debug: 0, + error: 3, + fatal: 4, + info: 1, + warn: 2, + }) +})