diff --git a/client/src/client/frame-runner.ts b/client/src/client/frame-runner.ts index d8a5ce89e6..d950edc631 100644 --- a/client/src/client/frame-runner.ts +++ b/client/src/client/frame-runner.ts @@ -26,6 +26,7 @@ export interface InitTestFrameArg { code: { contents?: string; editableContents?: string; + original?: { [id: string]: string }; }; getUserInput?: (fileName: string) => string; loadEnzyme?: () => void; @@ -33,6 +34,14 @@ export interface InitTestFrameArg { async function initTestFrame(e: InitTestFrameArg = { code: {} }) { const code = (e.code.contents || '').slice(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const __file = (id?: string) => { + if (id && e.code.original) { + return e.code.original[id]; + } else { + return code; + } + }; const editableContents = (e.code.editableContents || '').slice(); // __testEditable allows test authors to run tests against a transitory dom // element built using only the code in the editable region. diff --git a/client/src/client/workers/test-evaluator.ts b/client/src/client/workers/test-evaluator.ts index 13ea866e24..d7592b1ea5 100644 --- a/client/src/client/workers/test-evaluator.ts +++ b/client/src/client/workers/test-evaluator.ts @@ -63,6 +63,7 @@ interface TestEvaluatorEvent extends MessageEvent { code: { contents: string; editableContents: string; + original: { [id: string]: string }; }; removeComments: boolean; firstTest: unknown; diff --git a/client/src/templates/Challenges/utils/build.js b/client/src/templates/Challenges/utils/build.js index 68530884a5..b900aa4b45 100644 --- a/client/src/templates/Challenges/utils/build.js +++ b/client/src/templates/Challenges/utils/build.js @@ -47,10 +47,12 @@ function buildSourceMap(challengeFiles) { const source = challengeFiles.reduce( (sources, challengeFile) => { sources.index += challengeFile.source || challengeFile.contents; + sources.contents = sources.index; + sources.original[challengeFile.history[0]] = challengeFile.source; sources.editableContents += challengeFile.editableContents || ''; return sources; }, - { index: '', editableContents: '' } + { index: '', editableContents: '', original: {} } ); return source; } diff --git a/client/src/templates/Challenges/utils/frame.js b/client/src/templates/Challenges/utils/frame.js index c8d2939b42..5da71c9c66 100644 --- a/client/src/templates/Challenges/utils/frame.js +++ b/client/src/templates/Challenges/utils/frame.js @@ -111,15 +111,13 @@ const initTestFrame = frameReady => ctx => { waitForFrame(ctx) .then(async () => { const { sources, loadEnzyme } = ctx; - // default for classic challenges - // should not be used for modern - const code = { - contents: sources.index, - editableContents: sources.editableContents - }; // provide the file name and get the original source const getUserInput = fileName => toString(sources[fileName]); - await ctx.document.__initTestFrame({ code, getUserInput, loadEnzyme }); + await ctx.document.__initTestFrame({ + code: sources, + getUserInput, + loadEnzyme + }); frameReady(); }) .catch(handleDocumentNotFound); diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index ad8b25ef38..bbb379e90a 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -675,7 +675,11 @@ async function initializeTestRunner(build, sources, code, loadEnzyme) { await page.evaluate( async (code, sources, loadEnzyme) => { const getUserInput = fileName => sources[fileName]; - await document.__initTestFrame({ code, getUserInput, loadEnzyme }); + await document.__initTestFrame({ + code: sources, + getUserInput, + loadEnzyme + }); }, code, sources,