Skip to content

Commit

Permalink
feat(@power-doctest/javascript): support preTransform options
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 25, 2019
1 parent 9ec632e commit 20eacb1
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export interface PowerDoctestRunnerOptions {
// If runMode is any, anyone assertion is finished and resolve it
// In Both, anyone is failed and reject it
runMode?: "any" | "all";
// transform function
// set code => code function if need
// Apply this transform before power-doctest transform
preTransform?: (code:string) => string;
// Internal Option
powerDoctestCallbackFunctionName?: string;
}

Expand All @@ -37,6 +42,7 @@ export function run(code: string, options: PowerDoctestRunnerOptions = {}) {
const runMode = options.runMode || "all";
const timeout = options.timeout !== undefined ? options.timeout : 2000;
const postCallbackName = options.powerDoctestCallbackFunctionName || CALLBACK_FUNCTION_NAME;
const preTransform = options.preTransform ? options.preTransform : (code: string) => code;
const context = options.context || {};
return new Promise((resolve, reject) => {
let isSettled = false;
Expand Down Expand Up @@ -80,7 +86,7 @@ Also, you should consider to use { "runMode": "any" }` : ""}`));
};
process.on("uncaughtException", uncaughtException);
process.on("unhandledRejection", unhandledRejection as any);
const poweredCode = convertCode(code, {
const poweredCode = convertCode(preTransform(code), {
assertAfterCallbackName: postCallbackName
});
// total count of assert
Expand Down

0 comments on commit 20eacb1

Please sign in to comment.