|
| 1 | +import path from 'node:path'; |
| 2 | +import { buildAndGetResults, getFileBySuffix } from 'test-helper'; |
| 3 | +import { expect, test } from 'vitest'; |
| 4 | + |
| 5 | +test('should handle the crossing case import "@/css/button.css"', async () => { |
| 6 | + const fixturePath = path.resolve(__dirname, './js-import-css'); |
| 7 | + const { contents } = await buildAndGetResults({ fixturePath }); |
| 8 | + console.log(contents); |
| 9 | + const esmFiles = Object.keys(contents.esm); |
| 10 | + expect(esmFiles).toMatchInlineSnapshot(` |
| 11 | + [ |
| 12 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/esm/css/index.js", |
| 13 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/esm/module/index.js", |
| 14 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/esm/module/index.module.js", |
| 15 | + ] |
| 16 | + `); |
| 17 | + const cssIndexJs = getFileBySuffix(contents.esm, 'css/index.js'); |
| 18 | + expect(cssIndexJs).toMatchInlineSnapshot(` |
| 19 | + "import "./index.css"; |
| 20 | + " |
| 21 | + `); |
| 22 | + const cssModuleIndexJs = getFileBySuffix(contents.esm, 'module/index.js'); |
| 23 | + expect(cssModuleIndexJs).toMatchInlineSnapshot(` |
| 24 | + "import * as __WEBPACK_EXTERNAL_MODULE__index_module_js_6796f91d__ from "./index.module.js"; |
| 25 | + __WEBPACK_EXTERNAL_MODULE__index_module_js_6796f91d__["default"]; |
| 26 | + " |
| 27 | + `); |
| 28 | + |
| 29 | + const cjsFiles = Object.keys(contents.cjs); |
| 30 | + expect(cjsFiles).toMatchInlineSnapshot(` |
| 31 | + [ |
| 32 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/cjs/css/index.cjs", |
| 33 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/cjs/module/index.cjs", |
| 34 | + "<ROOT>/tests/integration/redirect/js-import-css/dist/cjs/module/index.module.cjs", |
| 35 | + ] |
| 36 | + `); |
| 37 | + const cssIndexCjs = getFileBySuffix(contents.cjs, 'css/index.cjs'); |
| 38 | + expect(cssIndexCjs).toContain('require("./index.css")'); |
| 39 | + const cssModuleIndexCjs = getFileBySuffix(contents.cjs, 'module/index.cjs'); |
| 40 | + expect(cssModuleIndexCjs).toContain('require("./index.module.cjs")'); |
| 41 | +}); |
0 commit comments