Skip to content

Commit

Permalink
test: rewrite test to work around Windows bug (#5945)
Browse files Browse the repository at this point in the history
We're not quite sure what's going on but the async import with `?one` fails on Windows
with node 22.12.0.
  • Loading branch information
serhalp authored Dec 13, 2024
1 parent 2ddadb2 commit dd96142
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/functions-utils/tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rm } from 'fs/promises'
import { readFile, rm } from 'fs/promises'
import { normalize } from 'path'
import { fileURLToPath, pathToFileURL } from 'url'
import { fileURLToPath } from 'url'

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

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

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

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

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

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

expect(func1()).toBe('one')
expect(func2()).toBe('two')
expect(file1).toContain('one')
expect(file2).toContain('two')
} finally {
await cpy(`${fixtureDir}/test.mjs.backup`, fixtureDir, { rename: 'test.mjs' })
await rm(`${fixtureDir}/test.mjs.backup`, { force: true })
Expand Down

0 comments on commit dd96142

Please sign in to comment.