mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix: indentation error reporting (#62182)
This commit is contained in:
committed by
GitHub
parent
dc0d39c548
commit
b80b849058
@@ -184,7 +184,7 @@ function* buildChallengeData(challengeData, options) {
|
||||
}
|
||||
}
|
||||
|
||||
function* executeTests(testRunner, tests, testTimeout = 5000) {
|
||||
export function* executeTests(testRunner, tests, testTimeout = 5000) {
|
||||
const testStrings = tests.map(test => test.testString);
|
||||
const rawResults = yield call(testRunner, testStrings, testTimeout);
|
||||
|
||||
@@ -216,16 +216,18 @@ function* executeTests(testRunner, tests, testTimeout = 5000) {
|
||||
if (err === 'timeout') {
|
||||
newTest.err = 'Test timed out';
|
||||
newTest.message = `${newTest.message} (${newTest.err})`;
|
||||
} else if (type === 'IndentationError' || type === 'SyntaxError') {
|
||||
} else {
|
||||
const { message, stack } = err;
|
||||
newTest.err = message + '\n' + stack;
|
||||
newTest.stack = stack;
|
||||
}
|
||||
|
||||
if (type === 'IndentationError' || type === 'SyntaxError') {
|
||||
const msgKey =
|
||||
type === 'IndentationError'
|
||||
? 'learn.indentation-error'
|
||||
: 'learn.syntax-error';
|
||||
newTest.message = `<p>${i18next.t(msgKey)}</p>`;
|
||||
} else {
|
||||
const { message, stack } = err;
|
||||
newTest.err = message + '\n' + stack;
|
||||
newTest.stack = stack;
|
||||
}
|
||||
|
||||
const withIndex = newTest.message.replace(/<p>/, `<p>${i + 1}. `);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { expectSaga } from 'redux-saga-test-plan';
|
||||
import { describe, it, vi } from 'vitest';
|
||||
|
||||
import { previewChallengeSaga, executeTests } from './execute-challenge-saga';
|
||||
|
||||
vi.mock('redux-saga/effects', async importOriginal => {
|
||||
const actual = await importOriginal();
|
||||
return {
|
||||
@@ -9,6 +11,12 @@ vi.mock('redux-saga/effects', async importOriginal => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('i18next', async () => ({
|
||||
default: {
|
||||
t: key => key
|
||||
}
|
||||
}));
|
||||
|
||||
const initialState = {
|
||||
challenge: { isBuildEnabled: true, isExecuting: false, challengeMeta: {} }
|
||||
};
|
||||
@@ -18,13 +26,11 @@ function reducer(state = initialState) {
|
||||
return state;
|
||||
}
|
||||
|
||||
import { previewChallengeSaga } from './execute-challenge-saga';
|
||||
|
||||
const challengeMounted = { type: 'challenge.challengeMounted' };
|
||||
const previewMounted = { type: 'challenge.previewMounted' };
|
||||
const resetChallenge = { type: 'challenge.resetChallenge' };
|
||||
|
||||
describe('execute-challenge-saga', () => {
|
||||
describe('previewChallengeSaga', () => {
|
||||
it('flushes logs on challengeMounted', () => {
|
||||
return expectSaga(previewChallengeSaga, challengeMounted)
|
||||
.withReducer(reducer)
|
||||
@@ -46,3 +52,38 @@ describe('execute-challenge-saga', () => {
|
||||
.silentRun();
|
||||
});
|
||||
});
|
||||
|
||||
describe('executeTests generator', () => {
|
||||
it('sets a special message for IndentationErrors', () => {
|
||||
const mockTestRunner = () => {
|
||||
return [
|
||||
{
|
||||
err: {
|
||||
type: 'IndentationError',
|
||||
message: 'Unexpected token',
|
||||
stack: '...'
|
||||
}
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
const tests = [{ testString: 'assert(true);', text: 'Test 1' }];
|
||||
|
||||
return expectSaga(executeTests, mockTestRunner, tests)
|
||||
.put({
|
||||
type: 'challenge.updateConsole',
|
||||
payload: '<p>1. learn.indentation-error</p>'
|
||||
})
|
||||
.returns([
|
||||
{
|
||||
err: 'Unexpected token\n...',
|
||||
text: 'Test 1',
|
||||
testString: 'assert(true);',
|
||||
running: false,
|
||||
message: '<p>learn.indentation-error</p>',
|
||||
stack: '...'
|
||||
}
|
||||
])
|
||||
.run();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user