feat(client): make all sources available in tests (#44725)

* feat: make all sources available in tests

The original contents of all files (index.html, script.js etc.) will be
accessible in tests.  For example __sources['index.html'] gets the
original html file and nothing else.

* feat: use __file to get user code
This commit is contained in:
Oliver Eyton-Williams
2022-02-15 18:59:31 +01:00
committed by GitHub
parent 137edc2fb3
commit cde1407f58
5 changed files with 23 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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);