Skip to content

Commit dd96142

Browse files
authored
test: rewrite test to work around Windows bug (#5945)
We're not quite sure what's going on but the async import with `?one` fails on Windows with node 22.12.0.
1 parent 2ddadb2 commit dd96142

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/functions-utils/tests/main.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { rm } from 'fs/promises'
1+
import { readFile, rm } from 'fs/promises'
22
import { normalize } from 'path'
3-
import { fileURLToPath, pathToFileURL } from 'url'
3+
import { fileURLToPath } from 'url'
44

55
import cpy from 'cpy'
66
import { pathExists } from 'path-exists'
@@ -77,21 +77,22 @@ test('Should copy a source file even if dist directory already exists', async ()
7777
test('Should overwrite dist file if it already exists', async () => {
7878
const dist = await getDist()
7979
const fixtureDir = `${FIXTURES_DIR}/file`
80+
const testModule = `${dist}/test.mjs`
8081

8182
await cpy(`${fixtureDir}/test.mjs`, fixtureDir, { rename: 'test.mjs.backup' })
8283

8384
try {
8485
await add(`${fixtureDir}/test.mjs`, dist)
8586

86-
const { func1 } = await import(`${pathToFileURL(`${dist}/test.mjs`).href}?one`)
87+
const file1 = await readFile(testModule, 'utf8')
8788

8889
await cpy(`${fixtureDir}/test_2.mjs`, fixtureDir, { rename: 'test.mjs' })
8990
await add(`${fixtureDir}/test.mjs`, dist)
9091

91-
const { func2 } = await import(`${pathToFileURL(`${dist}/test.mjs`).href}?two`)
92+
const file2 = await readFile(testModule, 'utf8')
9293

93-
expect(func1()).toBe('one')
94-
expect(func2()).toBe('two')
94+
expect(file1).toContain('one')
95+
expect(file2).toContain('two')
9596
} finally {
9697
await cpy(`${fixtureDir}/test.mjs.backup`, fixtureDir, { rename: 'test.mjs' })
9798
await rm(`${fixtureDir}/test.mjs.backup`, { force: true })

0 commit comments

Comments
 (0)