-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add typescript support by bundling processor with esbuild (#…
…2360) * feat(cli): add typescript support by bundling processor with esbuild * fix(cli): call ts handler function * refactor(cli): only allow typescript processor in non-lambda * feat(cli): handle error in ts bundling * refactor(cli): use original processor file name * test(cli): add basic tests for typescript support * fix(cli): only extract extname if processor exists * test(cli): add assert for error log
- Loading branch information
1 parent
db46e67
commit 6103717
Showing
9 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,71 @@ | ||
const tap = require('tap'); | ||
const { execute, returnTmpPath } = require('../cli/_helpers.js'); | ||
const { createHash } = require('crypto'); | ||
const fs = require('fs'); | ||
|
||
let reportFilePath; | ||
tap.beforeEach(async (t) => { | ||
reportFilePath = returnTmpPath( | ||
`report-${createHash('md5') | ||
.update(t.name) | ||
.digest('hex')}-${Date.now()}.json` | ||
); | ||
}); | ||
|
||
// tap.test('Can run a Typescript processor', async (t) => { | ||
// const [exitCode, output] = await execute([ | ||
// 'run', | ||
// '-o', | ||
// `${reportFilePath}`, | ||
// 'test/scripts/scenarios-typescript/lodash.yml' | ||
// ]); | ||
|
||
// t.equal(exitCode, 0, 'CLI should exit with code 0'); | ||
// t.ok( | ||
// output.stdout.includes('Got context using lodash: true'), | ||
// 'Should be able to use lodash in a scenario to get context' | ||
// ); | ||
// const json = JSON.parse(fs.readFileSync(reportFilePath, 'utf8')); | ||
|
||
// t.equal( | ||
// json.aggregate.counters['http.codes.200'], | ||
// 2, | ||
// 'Should have made 2 requests' | ||
// ); | ||
// t.equal( | ||
// json.aggregate.counters['hey_from_ts'], | ||
// 2, | ||
// 'Should have emitted 2 custom metrics from ts processor' | ||
// ); | ||
// }); | ||
|
||
tap.test( | ||
'Failure from a Typescript processor has a resolvable stack trace via source maps', | ||
async (t) => { | ||
const [exitCode, output] = await execute([ | ||
'run', | ||
'-o', | ||
`${reportFilePath}`, | ||
'test/scripts/scenarios-typescript/error.yml' | ||
]); | ||
|
||
t.equal(exitCode, 11, 'CLI should exit with code 11'); | ||
t.ok( | ||
output.stdout.includes('error_from_ts_processor'), | ||
'Should have logged error from ts processor' | ||
); | ||
|
||
// Search for the path | ||
const pathRegex = /\((.*?):\d+:\d+\)/; | ||
const match = output.stdout.match(pathRegex); | ||
|
||
// Extract the path if found | ||
const extractedPath = match ? match[1] : null; | ||
|
||
t.ok( | ||
extractedPath.includes('.ts'), | ||
'Should be using source maps to resolve the path to a .ts file' | ||
); | ||
t.ok(fs.existsSync(extractedPath), 'Error path should exist'); | ||
} | ||
); |
15 changes: 15 additions & 0 deletions
15
packages/artillery/test/scripts/scenarios-typescript/error.yml
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,15 @@ | ||
config: | ||
target: "http://asciiart.artillery.io:8080" | ||
phases: | ||
- duration: 2 | ||
arrivalRate: 1 | ||
name: "Phase 1" | ||
processor: "./processor.ts" | ||
variables: | ||
isTypescript: true | ||
|
||
scenarios: | ||
- flow: | ||
- function: processorWithError | ||
- get: | ||
url: "/" |
15 changes: 15 additions & 0 deletions
15
packages/artillery/test/scripts/scenarios-typescript/lodash.yml
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,15 @@ | ||
config: | ||
target: "http://asciiart.artillery.io:8080" | ||
phases: | ||
- duration: 2 | ||
arrivalRate: 1 | ||
name: "Phase 1" | ||
processor: "./processor.ts" | ||
variables: | ||
isTypescript: true | ||
|
||
scenarios: | ||
- flow: | ||
- function: myTest | ||
- get: | ||
url: "/" |
16 changes: 16 additions & 0 deletions
16
packages/artillery/test/scripts/scenarios-typescript/processor.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,16 @@ | ||
import _ from 'lodash'; | ||
|
||
export const myTest = async (context, ee, next) => { | ||
const isTypescript = _.get(context, 'vars.isTypescript'); | ||
|
||
console.log(`Got context using lodash: ${JSON.stringify(isTypescript)}`); | ||
|
||
ee.emit('counter', 'hey_from_ts', 1); | ||
|
||
next(); | ||
}; | ||
|
||
export const processorWithError = async (context, ee, next) => { | ||
throw new Error('error_from_ts_processor'); | ||
next(); | ||
}; |