Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Sep 14, 2024
1 parent 923465c commit 3fcfff1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/core/deps/dep-esm-comment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// import x from "x"
/** import x from "x" */
/**
* import x from "x"
*/
module.exports = { test: 'ok' }
5 changes: 5 additions & 0 deletions test/core/deps/dep-esm-comment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vitest/test-dep-esm-comment",
"type": "commonjs",
"exports": "./index.js"
}
1 change: 1 addition & 0 deletions test/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@vitest/expect": "workspace:*",
"@vitest/mocker": "workspace:*",
"@vitest/runner": "workspace:*",
"@vitest/test-dep-esm-comment": "file:./deps/dep-esm-comment",
"@vitest/test-dep1": "file:./deps/dep1",
"@vitest/test-dep2": "file:./deps/dep2",
"@vitest/utils": "workspace:*",
Expand Down
11 changes: 11 additions & 0 deletions test/core/test/dual-package-hazard.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createRequire } from 'node:module'
import { expect, test } from 'vitest'

// @ts-expect-error no ts
Expand All @@ -6,7 +7,17 @@ import * as dep1 from '@vitest/test-dep1'
// @ts-expect-error no ts
import * as dep2 from '@vitest/test-dep2'

// @ts-expect-error no ts
import depEsmComment from '@vitest/test-dep-esm-comment'

const require = createRequire(import.meta.url)

test('no dual package hazard by externalizing esm deps by default', async () => {
dep1.data.hello = 'world'
expect(dep2.data.hello).toBe('world')
})

test('externalize cjs with esm comment', async () => {
const depEsmCommentRequire = require('@vitest/test-dep-esm-comment')
expect(depEsmComment).toBe(depEsmCommentRequire)
})

0 comments on commit 3fcfff1

Please sign in to comment.