Skip to content

Commit

Permalink
test(e2e): use concurrent instead of serial for globContentJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 22, 2024
1 parent de00d5c commit 35b7781
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
25 changes: 15 additions & 10 deletions e2e/cases/performance/load-resource/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ test('should generate prefetch link when prefetch is defined', async () => {

const files = await rsbuild.unwrapOutputJSON();

const asyncFileName = Object.keys(files).find((file) =>
file.includes('/static/js/async/'),
const asyncFileName = Object.keys(files).find(
(file) =>
file.includes('/static/js/async/') && !file.endsWith('.LICENSE.txt'),
)!;
const [, content] = Object.entries(files).find(([name]) =>
name.endsWith('.html'),
Expand Down Expand Up @@ -66,8 +67,9 @@ test('should generate prefetch link correctly when assetPrefix do not have a pro

const files = await rsbuild.unwrapOutputJSON();

const asyncFileName = Object.keys(files).find((file) =>
file.includes('/static/js/async/'),
const asyncFileName = Object.keys(files).find(
(file) =>
file.includes('/static/js/async/') && !file.endsWith('.LICENSE.txt'),
)!;
const [, content] = Object.entries(files).find(([name]) =>
name.endsWith('.html'),
Expand Down Expand Up @@ -187,8 +189,9 @@ test('should generate preload link when preload is defined', async () => {

const files = await rsbuild.unwrapOutputJSON();

const asyncFileName = Object.keys(files).find((file) =>
file.includes('/static/js/async/'),
const asyncFileName = Object.keys(files).find(
(file) =>
file.includes('/static/js/async/') && !file.endsWith('.LICENSE.txt'),
)!;
const [, content] = Object.entries(files).find(([name]) =>
name.endsWith('.html'),
Expand Down Expand Up @@ -230,8 +233,9 @@ test('should generate preload link with crossOrigin', async () => {

const files = await rsbuild.unwrapOutputJSON();

const asyncFileName = Object.keys(files).find((file) =>
file.includes('/static/js/async/'),
const asyncFileName = Object.keys(files).find(
(file) =>
file.includes('/static/js/async/') && !file.endsWith('.LICENSE.txt'),
)!;
const [, content] = Object.entries(files).find(([name]) =>
name.endsWith('.html'),
Expand Down Expand Up @@ -270,8 +274,9 @@ test('should generate preload link without crossOrigin when same origin', async

const files = await rsbuild.unwrapOutputJSON();

const asyncFileName = Object.keys(files).find((file) =>
file.includes('/static/js/async/'),
const asyncFileName = Object.keys(files).find(
(file) =>
file.includes('/static/js/async/') && !file.endsWith('.LICENSE.txt'),
)!;
const [, content] = Object.entries(files).find(([name]) =>
name.endsWith('.html'),
Expand Down
6 changes: 4 additions & 2 deletions e2e/cases/source/alias-by-target/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ test('should allow to set alias by build target', async () => {
const files = await rsbuild.unwrapOutputJSON();
const fileNames = Object.keys(files);
const webIndex = fileNames.find(
(file) => file.includes('static/js') && file.includes('index.js'),
(file) => file.includes('static/js') && file.endsWith('index.js'),
);
const nodeIndex = fileNames.find(
(file) => file.includes('server/index') && file.endsWith('index.js'),
);
const nodeIndex = fileNames.find((file) => file.includes('server/index'));

expect(files[webIndex!]).toContain('for web target');
expect(files[nodeIndex!]).toContain('for node target');
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/source/multiple-entry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('should allow to set entry by build target', async () => {
const files = await rsbuild.unwrapOutputJSON();
const fileNames = Object.keys(files);
const webIndex = fileNames.find(
(file) => file.includes('static/js') && file.includes('index.js'),
(file) => file.includes('static/js') && file.endsWith('index.js'),
);
const nodeIndex = fileNames.find((file) => file.includes('server/index'));

Expand Down
10 changes: 7 additions & 3 deletions e2e/scripts/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export const globContentJSON = async (path: string, options?: GlobOptions) => {
const files = await glob(convertPath(join(path, '**/*')), options);
const ret: Record<string, string> = {};

for await (const file of files) {
ret[file] = await fse.readFile(file, 'utf-8');
}
await Promise.all(
files.map((file) =>
fse.readFile(file, 'utf-8').then((content) => {
ret[file] = content;
}),
),
);

return ret;
};
Expand Down

0 comments on commit 35b7781

Please sign in to comment.