This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remaining changes to support jest: - Hook jest command/environment in the `configuration-accessor` component. - Add `jest` as a valid recorder in schema - Add `jest` as a supported recorder in `receptor-file` component.
- Loading branch information
Showing
10 changed files
with
200 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
escape.mjs | ||
package.mjs | ||
mocha.mjs | ||
jest.mjs | ||
node.mjs | ||
process.mjs | ||
remote.mjs | ||
|
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,46 @@ | ||
import { coalesce } from "../../util/index.mjs"; | ||
import { convertFileUrlToPath } from "../../path/index.mjs"; | ||
import { toAbsoluteUrl } from "../../url/index.mjs"; | ||
import { escapeNodeOption, escapeShell } from "./escape.mjs"; | ||
import { generateParseSource, generateSplitTokens } from "./package.mjs"; | ||
|
||
const { canParseSource, parseSource } = generateParseSource("jest"); | ||
const { canSplitTokens, splitTokens } = generateSplitTokens("jest"); | ||
|
||
export const name = "jest"; | ||
export const recursive = null; | ||
|
||
export const doesSupportSource = canParseSource; | ||
export const doesSupportTokens = canSplitTokens; | ||
|
||
export const hookCommandSource = (source, shell, base) => { | ||
const groups = parseSource(source); | ||
return [ | ||
`${groups.before} --runInBand --setupFilesAfterEnv ${escapeShell( | ||
shell, | ||
convertFileUrlToPath(toAbsoluteUrl("lib/node/recorder-jest.mjs", base)), | ||
)}${groups.after}`, | ||
]; | ||
}; | ||
|
||
export const hookCommandTokens = (tokens, base) => { | ||
const { before, after } = splitTokens(tokens); | ||
return [ | ||
...before, | ||
"--runInBand", | ||
"--setupFilesAfterEnv", | ||
convertFileUrlToPath(toAbsoluteUrl("lib/node/recorder-jest.mjs", base)), | ||
...after, | ||
]; | ||
}; | ||
|
||
export const hookEnvironment = (env, base) => ({ | ||
...env, | ||
NODE_OPTIONS: `${coalesce( | ||
env, | ||
"NODE_OPTIONS", | ||
"", | ||
)} --experimental-vm-modules --experimental-loader=${escapeNodeOption( | ||
convertFileUrlToPath(toAbsoluteUrl("lib/node/loader-standalone.mjs", base)), | ||
)}`, | ||
}); |
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,49 @@ | ||
import { assertDeepEqual, assertEqual } from "../../__fixture__.mjs"; | ||
import { fileURLToPath } from "node:url"; | ||
import { | ||
doesSupportSource, | ||
doesSupportTokens, | ||
hookCommandSource, | ||
hookCommandTokens, | ||
hookEnvironment, | ||
} from "./jest.mjs"; | ||
|
||
const base = "file:///A:/base/"; | ||
const recorder_path = fileURLToPath( | ||
"file:///A:/base/lib/node/recorder-jest.mjs", | ||
); | ||
const loader_path = fileURLToPath( | ||
"file:///A:/base/lib/node/loader-standalone.mjs", | ||
); | ||
|
||
////////////////// | ||
// mocha --argv // | ||
////////////////// | ||
|
||
// source // | ||
assertEqual(doesSupportSource("jest --argv"), true); | ||
assertDeepEqual(hookCommandSource("jest --argv", "/bin/sh", base), [ | ||
`jest --runInBand --setupFilesAfterEnv ${recorder_path} --argv`, | ||
]); | ||
|
||
// tokens // | ||
assertEqual(doesSupportTokens(["jest", "--argv"]), true); | ||
assertDeepEqual(hookCommandTokens(["jest", "--argv"], base), [ | ||
"jest", | ||
"--runInBand", | ||
"--setupFilesAfterEnv", | ||
recorder_path, | ||
"--argv", | ||
]); | ||
|
||
///////////////////// | ||
// hookEnvironment // | ||
///////////////////// | ||
|
||
assertDeepEqual( | ||
hookEnvironment({ FOO: "bar", NODE_OPTIONS: "options" }, base), | ||
{ | ||
FOO: "bar", | ||
NODE_OPTIONS: `options --experimental-vm-modules --experimental-loader=${loader_path}`, | ||
}, | ||
); |
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,9 @@ | ||
import { default as process } from "node:process"; | ||
import "./error.mjs"; | ||
import { configuration } from "./configuration.mjs"; | ||
|
||
const { | ||
RecorderJest: { main }, | ||
} = await import("../../dist/bundles/recorder-cli.mjs"); | ||
|
||
main(process, configuration); |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
enum: | ||
- process | ||
- mocha | ||
- jest | ||
- manual | ||
- remote |
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,83 @@ | ||
import { | ||
writeFile as writeFileAsync, | ||
readdir as readdirAsync, | ||
} from "fs/promises"; | ||
import { platform as getPlatform } from "os"; | ||
import { strict as Assert } from "assert"; | ||
import { join as joinPath } from "path"; | ||
import { spawnStrictAsync } from "../../spawn.mjs"; | ||
import { runAsync } from "./__fixture__.mjs"; | ||
|
||
const { Set } = globalThis; | ||
|
||
const { deepEqual: assertDeepEqual } = Assert; | ||
|
||
await runAsync( | ||
null, | ||
{ | ||
command: [ | ||
getPlatform() === "win32" ? "npx.cmd" : "npx", | ||
"jest", | ||
"--testMatch", | ||
"**/*.test.mjs", | ||
], | ||
recorder: "jest", | ||
packages: { glob: "*" }, | ||
hooks: { | ||
esm: true, | ||
cjs: false, | ||
apply: true, | ||
http: false, | ||
}, | ||
}, | ||
async (repository) => { | ||
await spawnStrictAsync( | ||
getPlatform() === "win32" ? "npm.cmd" : "npm", | ||
["install", "jest"], | ||
{ cwd: repository, stdio: "inherit" }, | ||
); | ||
await writeFileAsync( | ||
joinPath(repository, "main.mjs"), | ||
` | ||
export const main = () => "main"; | ||
export const mainAsync = async () => "main"; | ||
`, | ||
"utf8", | ||
); | ||
await writeFileAsync( | ||
joinPath(repository, "main.test.mjs"), | ||
` | ||
import * as Jest from "@jest/globals"; | ||
import { main, mainAsync } from "./main.mjs"; | ||
const { test, expect } = Jest; | ||
test("main-sync", () => { | ||
expect(main()).toBe("main"); | ||
}); | ||
test("main-async", async () => { | ||
expect(await mainAsync()).toBe("main"); | ||
}); | ||
test("main-callback", (done) => { | ||
mainAsync().then((res) => { | ||
try { | ||
expect(res).toBe("main"); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
`, | ||
"utf8", | ||
); | ||
}, | ||
async (directory) => { | ||
assertDeepEqual( | ||
new Set(await readdirAsync(joinPath(directory, "tmp", "appmap", "jest"))), | ||
new Set([ | ||
"main-sync.appmap.json", | ||
"main-async.appmap.json", | ||
"main-callback.appmap.json", | ||
]), | ||
); | ||
}, | ||
); |