Skip to content

Commit 4eb1a3f

Browse files
authored
fix(bom): make sure self-contained TS scripts are bundled as expected (#3528)
1 parent 33743ad commit 4eb1a3f

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

examples/browser-load-testing-playwright/browser-load-test.ts

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { checkOutArtilleryCoreConceptsFlow } from './flows.js';
2-
31
export const config = {
42
target: 'https://www.artillery.io',
53
phases: [
@@ -9,7 +7,9 @@ export const config = {
97
}
108
],
119
engines: {
12-
playwright: {}
10+
playwright: {
11+
trace: true
12+
}
1313
}
1414
};
1515

@@ -25,6 +25,34 @@ export const scenarios = [
2525
{
2626
engine: 'playwright',
2727
name: 'check_out_core_concepts_scenario',
28-
testFunction: checkOutArtilleryCoreConceptsFlow
28+
testFunction: async function checkOutArtilleryCoreConceptsFlow(
29+
page,
30+
userContext,
31+
events,
32+
test
33+
) {
34+
await test.step('Go to Artillery', async () => {
35+
const requestPromise = page.waitForRequest('https://artillery.io/');
36+
await page.goto('https://artillery.io/');
37+
const req = await requestPromise;
38+
});
39+
await test.step('Go to docs', async () => {
40+
const docs = await page.getByRole('link', { name: 'Docs' });
41+
await docs.click();
42+
await page.waitForURL('https://www.artillery.io/docs');
43+
});
44+
45+
await test.step('Go to core concepts', async () => {
46+
await page
47+
.getByRole('link', {
48+
name: 'Review core concepts'
49+
})
50+
.click();
51+
52+
await page.waitForURL(
53+
'https://www.artillery.io/docs/get-started/core-concepts'
54+
);
55+
});
56+
}
2957
}
3058
];

packages/artillery/lib/platform/aws-ecs/legacy/bom.js

+4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ function getCustomJsDependencies(context, next) {
297297
// Could be JSON files too.
298298
context.localFilePaths = context.localFilePaths.concat(tree);
299299
context.npmModules = context.npmModules.concat(reduced);
300+
// Remove duplicate entries for the same file when invoked on a single .ts script
301+
// See line 44 - the config.processor property is always set on .ts files, which leads to
302+
// multiple entries in the localFilePaths array for the same file
303+
context.localFilePaths = _.uniq(context.localFilePaths);
300304
debug('got custom JS dependencies');
301305
return next(null, context);
302306
} else {

packages/artillery/test/unit/fargate-bom.test.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
'use strict';
22

3-
const { test, afterEach } = require('tap');
4-
const { applyScriptChanges } = require('../../lib/platform/aws-ecs/legacy/bom');
3+
const promisify = require('util').promisify;
4+
const path = require('path');
5+
const { test } = require('tap');
6+
const {
7+
createBOM,
8+
applyScriptChanges
9+
} = require('../../lib/platform/aws-ecs/legacy/bom');
510

611
// TODO: Add tests for other functions in bom.js
712

13+
test('Self-contained .ts script with no dependencies', async (t) => {
14+
const inputFilename = 'browser-load-test.ts';
15+
const inputScript = path.join(
16+
__dirname,
17+
'../../../../examples/browser-load-testing-playwright',
18+
inputFilename
19+
);
20+
const createBOMAsync = promisify(createBOM);
21+
const bom = await createBOMAsync(inputScript, [], {
22+
scenarioPath: inputScript,
23+
flags: {}
24+
});
25+
console.log(bom);
26+
t.equal(
27+
bom.files.length,
28+
1,
29+
'Input file is expected to have no dependencies'
30+
);
31+
t.equal(bom.files[0].orig.endsWith(inputFilename), true);
32+
t.equal(
33+
bom.files[0].noPrefix,
34+
inputFilename,
35+
'Unprefixed filename should be the same as the input filename'
36+
);
37+
});
38+
839
test('applyScriptChanges should resolve config templates with cli variables', async (t) => {
940
// Arrange
1041
global.artillery.testRunId = 'bombolini_id_1234567890';

0 commit comments

Comments
 (0)