forked from web-infra-dev/modern.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(builder): ignore e2e tests that rspack does not need attention (w…
- Loading branch information
Showing
13 changed files
with
366 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...lder-cli/builder-cli-rspack/index.test.ts → ...i/builder-cli-rspack/index.rspack.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...der-cli/builder-cli-webpack/index.test.ts → ...builder-cli-webpack/index.webpack.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import path from 'path'; | ||
import { build } from '@scripts/shared'; | ||
import { expect, test } from '@modern-js/e2e/playwright'; | ||
import { ensureDirSync, copySync } from 'fs-extra'; | ||
import { SharedTransformImport } from '@modern-js/builder-shared'; | ||
import { BuilderConfig } from '@modern-js/builder-webpack-provider'; | ||
|
||
export const cases: Parameters<typeof shareTest>[] = [ | ||
[ | ||
`camelCase test`, | ||
'./src/camel.js', | ||
{ | ||
libraryName: 'foo', | ||
libraryDirectory: 'lib', | ||
camelToDashComponentName: false, | ||
}, | ||
], | ||
[ | ||
`kebab-case test`, | ||
'./src/kebab.js', | ||
{ | ||
libraryName: 'foo', | ||
libraryDirectory: 'lib', | ||
camelToDashComponentName: true, | ||
}, | ||
], | ||
[ | ||
'transform to named import', | ||
'./src/named.js', | ||
{ | ||
libraryName: 'foo', | ||
libraryDirectory: 'lib', | ||
camelToDashComponentName: true, | ||
transformToDefaultImport: false, | ||
}, | ||
], | ||
]; | ||
|
||
export function findEntry( | ||
files: Record<string, string>, | ||
name = 'index', | ||
): string { | ||
for (const key of Reflect.ownKeys(files) as string[]) { | ||
if (key.includes(`dist/static/js/${name}`) && key.endsWith('.js')) { | ||
return key; | ||
} | ||
} | ||
|
||
throw new Error('unreacheable'); | ||
} | ||
|
||
export function copyPkgToNodeModules() { | ||
const nodeModules = path.resolve(__dirname, 'node_modules'); | ||
|
||
ensureDirSync(nodeModules); | ||
copySync(path.resolve(__dirname, 'foo'), path.resolve(nodeModules, 'foo')); | ||
} | ||
|
||
export function shareTest( | ||
msg: string, | ||
entry: string, | ||
transformImport: SharedTransformImport, | ||
otherConfigs: { | ||
plugins?: any[]; | ||
} = {}, | ||
) { | ||
const setupConfig = { | ||
cwd: __dirname, | ||
entry: { | ||
index: entry, | ||
}, | ||
}; | ||
const config: BuilderConfig = { | ||
source: { | ||
transformImport: [transformImport], | ||
}, | ||
performance: { | ||
chunkSplit: { | ||
strategy: 'all-in-one', | ||
}, | ||
}, | ||
}; | ||
|
||
test(msg, async () => { | ||
const builder = await build({ | ||
...setupConfig, | ||
...otherConfigs, | ||
builderConfig: { ...config }, | ||
}); | ||
const files = await builder.unwrapOutputJSON(false); | ||
expect(files[findEntry(files)]).toContain('transformImport test succeed'); | ||
}); | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/e2e/builder/cases/source/plugin-import/index.rspack.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import path from 'path'; | ||
import { build } from '@scripts/shared'; | ||
import { expect, test } from '@modern-js/e2e/playwright'; | ||
import { cases, shareTest, copyPkgToNodeModules, findEntry } from './helper'; | ||
|
||
test('should import with template config', async () => { | ||
copyPkgToNodeModules(); | ||
|
||
const builder = await build({ | ||
cwd: __dirname, | ||
entry: { index: path.resolve(__dirname, './src/index.js') }, | ||
builderConfig: { | ||
source: { | ||
transformImport: [ | ||
{ | ||
libraryName: 'foo', | ||
customName: 'foo/lib/{{ member }}', | ||
}, | ||
], | ||
}, | ||
performance: { | ||
chunkSplit: { | ||
strategy: 'all-in-one', | ||
}, | ||
}, | ||
}, | ||
}); | ||
const files = await builder.unwrapOutputJSON(false); | ||
const entry = findEntry(files); | ||
expect(files[entry]).toContain('transformImport test succeed'); | ||
}); | ||
|
||
cases.forEach(c => { | ||
const [name, entry, config] = c; | ||
shareTest(`${name}-rspack`, entry, config); | ||
}); |
Oops, something went wrong.