Skip to content

Commit

Permalink
test: add failing test for vitest-dev#6297
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 8, 2024
1 parent a7be50d commit 5252784
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/coverage-test/fixtures/src/cjs-package/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("./target");
module.exports = "Entry here"
5 changes: 5 additions & 0 deletions test/coverage-test/fixtures/src/cjs-package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "cjs-package",
"main": "./entry.js",
"type": "commonjs"
}
9 changes: 9 additions & 0 deletions test/coverage-test/fixtures/src/cjs-package/target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

module.exports = {
debug: 0,
info: 1,
warn: 2,
error: 3,
fatal: 4,
};
14 changes: 14 additions & 0 deletions test/coverage-test/test/file-outside-vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})

0 comments on commit 5252784

Please sign in to comment.