|
1 | 1 | import { join } from 'node:path'; |
2 | 2 | import stripAnsi from 'strip-ansi'; |
3 | | -import { buildAndGetResults, proxyConsole } from 'test-helper'; |
| 3 | +import { buildAndGetResults, proxyConsole, queryContent } from 'test-helper'; |
4 | 4 | import { expect, test } from 'vitest'; |
5 | 5 | import { composeModuleImportWarn } from '../../../packages/core/src/config'; |
6 | 6 |
|
@@ -77,17 +77,31 @@ test('require ESM from CJS', async () => { |
77 | 77 |
|
78 | 78 | test('user externals', async () => { |
79 | 79 | // Ensure the priority of user externals higher than others. |
80 | | - // - memfs: userExternalsConfig > targetExternalsConfig |
81 | | - // - lodash-es/zip: userExternalsConfig > autoExternalConfig |
| 80 | + // - "memfs": userExternalsConfig > targetExternalsConfig |
| 81 | + // - "lodash-es/zip": userExternalsConfig > autoExternalConfig |
| 82 | + // - "./foo2": userExternalsConfig > bundlelessExternalConfig |
| 83 | + |
82 | 84 | const fixturePath = join(__dirname, 'user-externals'); |
83 | | - const { entries } = await buildAndGetResults({ fixturePath }); |
84 | | - expect(entries.esm).toMatchInlineSnapshot( |
| 85 | + const { entries, contents } = await buildAndGetResults({ fixturePath }); |
| 86 | + expect(entries.esm0).toMatchInlineSnapshot( |
85 | 87 | ` |
86 | | - "import * as __WEBPACK_EXTERNAL_MODULE_memfs__ from "memfs"; |
| 88 | + "import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs"; |
87 | 89 | import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; |
88 | | - import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_zip_b8981481__ from "lodash-es/zip"; |
89 | | - console.log(__WEBPACK_EXTERNAL_MODULE_memfs__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_es_zip_b8981481__["default"]); |
| 90 | + import * as __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__ from "lodash/zip"; |
| 91 | + const foo = 'foo'; |
| 92 | + console.log(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__["default"], foo); |
90 | 93 | " |
91 | 94 | `, |
92 | 95 | ); |
| 96 | + |
| 97 | + expect( |
| 98 | + queryContent(contents.esm1!, 'index.js', { basename: true }).content, |
| 99 | + ).toMatchInlineSnapshot(` |
| 100 | + "import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs"; |
| 101 | + import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; |
| 102 | + import * as __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__ from "lodash/zip"; |
| 103 | + import * as __WEBPACK_EXTERNAL_MODULE__foo2_1d132755__ from "./foo2"; |
| 104 | + console.log(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__["default"], __WEBPACK_EXTERNAL_MODULE__foo2_1d132755__.foo); |
| 105 | + " |
| 106 | + `); |
93 | 107 | }); |
0 commit comments