|
| 1 | +import path from 'node:path'; |
| 2 | +import stripAnsi from 'strip-ansi'; |
| 3 | +import { buildAndGetResults, proxyConsole, queryContent } from 'test-helper'; |
| 4 | +import { expect, test } from 'vitest'; |
| 5 | + |
| 6 | +test('redirect.js default', async () => { |
| 7 | + const fixturePath = path.resolve(__dirname, './js-not-resolve'); |
| 8 | + const { logs } = proxyConsole(); |
| 9 | + const contents = (await buildAndGetResults({ fixturePath, lib: ['esm0'] })) |
| 10 | + .contents; |
| 11 | + |
| 12 | + const logStrings = logs |
| 13 | + .map((log) => stripAnsi(log)) |
| 14 | + .filter((log) => log.startsWith('warn')) |
| 15 | + .sort(); |
| 16 | + |
| 17 | + expect(logStrings).toMatchInlineSnapshot( |
| 18 | + ` |
| 19 | + [ |
| 20 | + "warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 21 | + "warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 22 | + "warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 23 | + ] |
| 24 | + `, |
| 25 | + ); |
| 26 | + |
| 27 | + const { content: indexContent } = queryContent( |
| 28 | + contents.esm0!, |
| 29 | + /esm\/index\.js/, |
| 30 | + ); |
| 31 | + |
| 32 | + expect(indexContent).toMatchInlineSnapshot(` |
| 33 | + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; |
| 34 | + import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; |
| 35 | + import * as __WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__ from "./foo.js"; |
| 36 | + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); |
| 37 | + export { src_rslib_entry_ as default }; |
| 38 | + " |
| 39 | + `); |
| 40 | +}); |
| 41 | + |
| 42 | +test('redirect.js.path false', async () => { |
| 43 | + const fixturePath = path.resolve(__dirname, './js-not-resolve'); |
| 44 | + const { logs } = proxyConsole(); |
| 45 | + const contents = (await buildAndGetResults({ fixturePath, lib: ['esm1'] })) |
| 46 | + .contents; |
| 47 | + |
| 48 | + const logStrings = logs |
| 49 | + .map((log) => stripAnsi(log)) |
| 50 | + .filter((log) => log.startsWith('warn')); |
| 51 | + |
| 52 | + expect(logStrings.length).toBe(0); |
| 53 | + |
| 54 | + const { content: indexContent } = queryContent( |
| 55 | + contents.esm1!, |
| 56 | + /esm\/index\.js/, |
| 57 | + ); |
| 58 | + |
| 59 | + expect(indexContent).toMatchInlineSnapshot(` |
| 60 | + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; |
| 61 | + import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; |
| 62 | + import * as __WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__ from "./foo.js"; |
| 63 | + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); |
| 64 | + export { src_rslib_entry_ as default }; |
| 65 | + " |
| 66 | + `); |
| 67 | +}); |
| 68 | + |
| 69 | +test('redirect.js.extension: false', async () => { |
| 70 | + const fixturePath = path.resolve(__dirname, './js-not-resolve'); |
| 71 | + const { logs } = proxyConsole(); |
| 72 | + const contents = (await buildAndGetResults({ fixturePath, lib: ['esm2'] })) |
| 73 | + .contents; |
| 74 | + |
| 75 | + const logStrings = logs |
| 76 | + .map((log) => stripAnsi(log)) |
| 77 | + .filter((log) => log.startsWith('warn')) |
| 78 | + .sort(); |
| 79 | + |
| 80 | + expect(logStrings).toMatchInlineSnapshot( |
| 81 | + ` |
| 82 | + [ |
| 83 | + "warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 84 | + "warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 85 | + "warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", |
| 86 | + ] |
| 87 | + `, |
| 88 | + ); |
| 89 | + |
| 90 | + const { content: indexContent } = queryContent( |
| 91 | + contents.esm2!, |
| 92 | + /esm\/index\.js/, |
| 93 | + ); |
| 94 | + |
| 95 | + expect(indexContent).toMatchInlineSnapshot(` |
| 96 | + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; |
| 97 | + import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; |
| 98 | + import * as __WEBPACK_EXTERNAL_MODULE__foo_23da6eef__ from "./foo"; |
| 99 | + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_23da6eef__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); |
| 100 | + export { src_rslib_entry_ as default }; |
| 101 | + " |
| 102 | + `); |
| 103 | +}); |
0 commit comments