Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/rspack-test-tools/src/helper/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const isValidCaseDirectory = (name: string) =>
!name.startsWith('_') && !name.startsWith('.') && name !== 'node_modules';

export function describeByWalk(
/**
* The test file absolute path.
*/
testFile: string,
createCase: (name: string, src: string, dist: string) => void,
options: {
Expand All @@ -30,6 +33,7 @@ export function describeByWalk(
options.source || path.join(path.dirname(testFile), `${testId}Cases`);

const testSourceId = path.basename(sourceBase);
const absoluteTestDir = path.join(testFile, '..');
Comment thread
9aoy marked this conversation as resolved.
Outdated

const distBase =
options.dist || path.join(path.dirname(testFile), 'js', testId);
Expand Down Expand Up @@ -75,8 +79,21 @@ export function describeByWalk(
.split('.')
.shift()!,
);
let suiteName = name;

describeFn(name, () => {
// support filter test by absolute path
if (process.env.testFilter?.includes(absoluteTestDir)) {
const absoluteName = path.join(
absoluteTestDir,
testSourceId,
caseName,
);
if (absoluteName.includes(process.env.testFilter!)) {
suiteName = absoluteName;
Comment thread
9aoy marked this conversation as resolved.
Outdated
}
}

describeFn(suiteName, () => {
const source = path.join(sourceBase, caseName);
let dist = '';
if (absoluteDist) {
Expand All @@ -89,7 +106,7 @@ export function describeByWalk(
dist = path.join(sourceBase, caseName, relativeDist);
}
}
createCase(name, source, dist);
createCase(suiteName, source, dist);
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion tests/rspack-test/Cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const tempDir = path.resolve(__dirname, `./js/temp`);

// Run tests rspack-test/tests/cacheCases in target async-node
describeByWalk(
"cache",
path.resolve(__dirname, "./cache"),
Comment thread
9aoy marked this conversation as resolved.
Outdated
(name, src, dist) => {
createCacheCase(name, src, dist, "async-node", path.join(tempDir, name));
},
Expand Down
19 changes: 10 additions & 9 deletions tests/rspack-test/rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const wasmConfig = process.env.WASM && defineProject({
maxConcurrency: 1,
});

const testFilter = process.argv.includes("--test") || process.argv.includes("-t")
? process.argv[
(process.argv.includes("-t")
? process.argv.indexOf("-t")
: process.argv.indexOf("--test")) + 1
]
: undefined;

const sharedConfig = defineProject({
setupFiles: setupFilesAfterEnv,
testTimeout: process.env.CI ? 60000 : 30000,
Expand Down Expand Up @@ -75,14 +83,7 @@ const sharedConfig = defineProject({
RSPACK_DEV: 'false',
RSPACK_EXPERIMENTAL: 'true',
RSPACK_CONFIG_VALIDATE: "strict",
testFilter:
process.argv.includes("--test") || process.argv.includes("-t")
? process.argv[
(process.argv.includes("-t")
? process.argv.indexOf("-t")
: process.argv.indexOf("--test")) + 1
]
: undefined,
testFilter,
printLogger: process.env.DEBUG === "test" ? 'true' : 'false',
__TEST_PATH__: __dirname,
__TEST_FIXTURES_PATH__: path.resolve(__dirname, "fixtures"),
Expand Down Expand Up @@ -112,7 +113,7 @@ export default defineConfig({
RSPACK_HOT_TEST: 'true',
},
}],
reporters: ['default'],
reporters: testFilter ? ['verbose'] : ['default'],
hideSkippedTests: true,
pool: {
maxWorkers: process.env.WASM ? 1 : "80%",
Expand Down
Loading