|
1 | | -import { rm } from 'fs/promises' |
| 1 | +import { readFile, rm } from 'fs/promises' |
2 | 2 | import { normalize } from 'path' |
3 | | -import { fileURLToPath, pathToFileURL } from 'url' |
| 3 | +import { fileURLToPath } from 'url' |
4 | 4 |
|
5 | 5 | import cpy from 'cpy' |
6 | 6 | import { pathExists } from 'path-exists' |
@@ -77,21 +77,22 @@ test('Should copy a source file even if dist directory already exists', async () |
77 | 77 | test('Should overwrite dist file if it already exists', async () => { |
78 | 78 | const dist = await getDist() |
79 | 79 | const fixtureDir = `${FIXTURES_DIR}/file` |
| 80 | + const testModule = `${dist}/test.mjs` |
80 | 81 |
|
81 | 82 | await cpy(`${fixtureDir}/test.mjs`, fixtureDir, { rename: 'test.mjs.backup' }) |
82 | 83 |
|
83 | 84 | try { |
84 | 85 | await add(`${fixtureDir}/test.mjs`, dist) |
85 | 86 |
|
86 | | - const { func1 } = await import(`${pathToFileURL(`${dist}/test.mjs`).href}?one`) |
| 87 | + const file1 = await readFile(testModule, 'utf8') |
87 | 88 |
|
88 | 89 | await cpy(`${fixtureDir}/test_2.mjs`, fixtureDir, { rename: 'test.mjs' }) |
89 | 90 | await add(`${fixtureDir}/test.mjs`, dist) |
90 | 91 |
|
91 | | - const { func2 } = await import(`${pathToFileURL(`${dist}/test.mjs`).href}?two`) |
| 92 | + const file2 = await readFile(testModule, 'utf8') |
92 | 93 |
|
93 | | - expect(func1()).toBe('one') |
94 | | - expect(func2()).toBe('two') |
| 94 | + expect(file1).toContain('one') |
| 95 | + expect(file2).toContain('two') |
95 | 96 | } finally { |
96 | 97 | await cpy(`${fixtureDir}/test.mjs.backup`, fixtureDir, { rename: 'test.mjs' }) |
97 | 98 | await rm(`${fixtureDir}/test.mjs.backup`, { force: true }) |
|
0 commit comments