fix(client): remove JS comments from user code for tests (#41873)
* Removes comments in js challanges by default * fix local-scope-and-functions test regex * fix all languages * revert language changes * removed unnecessary removeJSComments from challenges * fix challanges in other languages * removed removeJSComments from all challanges
This commit is contained in:
committed by
GitHub
parent
ebe8f99345
commit
db369fbed1
@ -38,6 +38,7 @@ export const ChallengeNode = PropTypes.shape({
|
|||||||
helpCategory: PropTypes.string,
|
helpCategory: PropTypes.string,
|
||||||
instructions: PropTypes.string,
|
instructions: PropTypes.string,
|
||||||
isComingSoon: PropTypes.bool,
|
isComingSoon: PropTypes.bool,
|
||||||
|
removeComments: PropTypes.bool,
|
||||||
isLocked: PropTypes.bool,
|
isLocked: PropTypes.bool,
|
||||||
isPrivate: PropTypes.bool,
|
isPrivate: PropTypes.bool,
|
||||||
order: PropTypes.number,
|
order: PropTypes.number,
|
||||||
|
@ -160,6 +160,7 @@ class ShowClassic extends Component {
|
|||||||
files,
|
files,
|
||||||
fields: { tests },
|
fields: { tests },
|
||||||
challengeType,
|
challengeType,
|
||||||
|
removeComments,
|
||||||
helpCategory
|
helpCategory
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -171,6 +172,7 @@ class ShowClassic extends Component {
|
|||||||
updateChallengeMeta({
|
updateChallengeMeta({
|
||||||
...challengeMeta,
|
...challengeMeta,
|
||||||
title,
|
title,
|
||||||
|
removeComments,
|
||||||
challengeType,
|
challengeType,
|
||||||
helpCategory
|
helpCategory
|
||||||
});
|
});
|
||||||
@ -365,6 +367,7 @@ export const query = graphql`
|
|||||||
title
|
title
|
||||||
description
|
description
|
||||||
instructions
|
instructions
|
||||||
|
removeComments
|
||||||
challengeType
|
challengeType
|
||||||
helpCategory
|
helpCategory
|
||||||
videoUrl
|
videoUrl
|
||||||
|
@ -87,6 +87,7 @@ export function* executeChallengeSaga({
|
|||||||
const protect = isLoopProtected(challengeMeta);
|
const protect = isLoopProtected(challengeMeta);
|
||||||
const buildData = yield buildChallengeData(challengeData, {
|
const buildData = yield buildChallengeData(challengeData, {
|
||||||
preview: false,
|
preview: false,
|
||||||
|
removeComments: challengeMeta.removeComments,
|
||||||
protect
|
protect
|
||||||
});
|
});
|
||||||
const document = yield getContext('document');
|
const document = yield getContext('document');
|
||||||
@ -201,6 +202,7 @@ function* previewChallengeSaga({ flushLogs = true } = {}) {
|
|||||||
const protect = isLoopProtected(challengeMeta);
|
const protect = isLoopProtected(challengeMeta);
|
||||||
const buildData = yield buildChallengeData(challengeData, {
|
const buildData = yield buildChallengeData(challengeData, {
|
||||||
preview: true,
|
preview: true,
|
||||||
|
removeComments: challengeMeta.removeComments,
|
||||||
protect
|
protect
|
||||||
});
|
});
|
||||||
// evaluate the user code in the preview frame or in the worker
|
// evaluate the user code in the preview frame or in the worker
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
import frameRunnerData from '../../../../../config/client/frame-runner.json';
|
import frameRunnerData from '../../../../../config/client/frame-runner.json';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import testEvaluatorData from '../../../../../config/client/test-evaluator.json';
|
import testEvaluatorData from '../../../../../config/client/test-evaluator.json';
|
||||||
|
import { removeJSComments } from '../../../utils/curriculum-helpers';
|
||||||
|
|
||||||
const { filename: runner } = frameRunnerData;
|
const { filename: runner } = frameRunnerData;
|
||||||
const { filename: testEvaluator } = testEvaluatorData;
|
const { filename: testEvaluator } = testEvaluatorData;
|
||||||
@ -164,16 +165,27 @@ export function buildJSChallenge({ files }, options) {
|
|||||||
.map(pipeLine);
|
.map(pipeLine);
|
||||||
return Promise.all(finalFiles)
|
return Promise.all(finalFiles)
|
||||||
.then(checkFilesErrors)
|
.then(checkFilesErrors)
|
||||||
.then(files => ({
|
.then(files => {
|
||||||
challengeType: challengeTypes.js,
|
let build = files
|
||||||
build: files
|
|
||||||
.reduce(
|
.reduce(
|
||||||
(body, file) => [...body, file.head, file.contents, file.tail],
|
(body, file) => [...body, file.head, file.contents, file.tail],
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
.join('\n'),
|
.join('\n');
|
||||||
sources: buildSourceMap(files)
|
let sources = buildSourceMap(files);
|
||||||
}));
|
if (options?.removeComments !== false) {
|
||||||
|
build = removeJSComments(build);
|
||||||
|
sources = {
|
||||||
|
...sources,
|
||||||
|
index: removeJSComments(sources.index)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
challengeType: challengeTypes.js,
|
||||||
|
build,
|
||||||
|
sources
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildBackendChallenge({ url }) {
|
export function buildBackendChallenge({ url }) {
|
||||||
|
@ -5,7 +5,7 @@ const removeHtmlComments = str => str.replace(/<!--[\s\S]*?(-->|$)/g, '');
|
|||||||
|
|
||||||
const removeCssComments = str => str.replace(/\/\*[\s\S]+?\*\//g, '');
|
const removeCssComments = str => str.replace(/\/\*[\s\S]+?\*\//g, '');
|
||||||
|
|
||||||
const removeJSComments = codeStr => {
|
export const removeJSComments = codeStr => {
|
||||||
// Note: removes trailing new lines and tailing spaces at end of lines
|
// Note: removes trailing new lines and tailing spaces at end of lines
|
||||||
const options = {
|
const options = {
|
||||||
comments: false,
|
comments: false,
|
||||||
@ -30,7 +30,6 @@ const removeWhiteSpace = (str = '') => {
|
|||||||
const curriculumHelpers = {
|
const curriculumHelpers = {
|
||||||
removeHtmlComments,
|
removeHtmlComments,
|
||||||
removeCssComments,
|
removeCssComments,
|
||||||
removeJSComments,
|
|
||||||
removeWhiteSpace
|
removeWhiteSpace
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* global describe it expect */
|
/* global describe it expect */
|
||||||
|
|
||||||
import __testHelpers from './curriculum-helpers';
|
import __testHelpers, { removeJSComments } from './curriculum-helpers';
|
||||||
import jsTestValues from './__fixtures/curriculum-helpers-javascript';
|
import jsTestValues from './__fixtures/curriculum-helpers-javascript';
|
||||||
import cssTestValues from './__fixtures/curriculum-helpers-css';
|
import cssTestValues from './__fixtures/curriculum-helpers-css';
|
||||||
import htmlTestValues from './__fixtures/curriculum-helpers-html';
|
import htmlTestValues from './__fixtures/curriculum-helpers-html';
|
||||||
@ -40,7 +40,6 @@ describe('removeWhiteSpace', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('removeJSComments', () => {
|
describe('removeJSComments', () => {
|
||||||
const { removeJSComments } = __testHelpers;
|
|
||||||
it('returns a string', () => {
|
it('returns a string', () => {
|
||||||
expect(typeof removeJSComments('const should = "return a string"')).toBe(
|
expect(typeof removeJSComments('const should = "return a string"')).toBe(
|
||||||
'string'
|
'string'
|
||||||
|
@ -65,7 +65,7 @@ assert.deepEqual(copyMachine(['it works'], 3), [
|
|||||||
`copyMachine` 函数中应对 `arr` 使用展开运算符(`spread operator`)。
|
`copyMachine` 函数中应对 `arr` 使用展开运算符(`spread operator`)。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(__helpers.removeJSComments(code).match(/\.\.\.arr/));
|
assert(code.match(/\.\.\.arr/));
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
@ -3,6 +3,7 @@ id: bd7123c9c441eddfaeb4bdef
|
|||||||
title: 给代码添加注释
|
title: 给代码添加注释
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
||||||
|
removeComments: false
|
||||||
forumTopicId: 16783
|
forumTopicId: 16783
|
||||||
dashedName: comment-your-javascript-code
|
dashedName: comment-your-javascript-code
|
||||||
---
|
---
|
||||||
|
@ -45,7 +45,7 @@ assert.throws(declared, ReferenceError);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(
|
/functionmyLocalScope\(\)\{.*(var|let|const)myVar[\s\S]*}/.test(
|
||||||
__helpers.removeWhiteSpace(code)
|
__helpers.removeWhiteSpace(code)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -66,9 +66,7 @@ assert.equal(sum([2, 3, 4, 5], 3), 9);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1
|
sum.toString().match(/sum\(.*\)/g).length > 1
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -59,9 +59,7 @@ assert.deepStrictEqual(countdown(5), [5, 4, 3, 2, 1]);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/)
|
countdown.toString().match(/countdown\s*\(.+\)/)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -26,9 +26,7 @@ assert(Array.isArray(rangeOfNumbers(5, 10)));
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -36,9 +34,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
rangeOfNumbers.toString().match(/rangeOfNumbers\s*\(.+\)/)
|
||||||
.removeJSComments(rangeOfNumbers.toString())
|
|
||||||
.match(/rangeOfNumbers\s*\(.+\)/)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ dashedName: understanding-the-differences-between-the-freecodecamp-and-browser-c
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers.removeWhiteSpace(code).match(/console.clear\(\)/)
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
|
||||||
.match(/console.clear\(\)/)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ const myPromise = new Promise((resolve, reject) => {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g
|
/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -44,9 +42,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
|
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -43,9 +43,7 @@ const { name, age } = user;
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -53,9 +51,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -65,9 +61,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -39,7 +39,7 @@ const person = {
|
|||||||
不应使用传统的函数定义方法。
|
不应使用传统的函数定义方法。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
(getUserInput) => assert(!__helpers.removeJSComments(code).match(/function/));
|
(getUserInput) => assert(!code.match(/function/));
|
||||||
```
|
```
|
||||||
|
|
||||||
`setGear` 应是一个声明函数。
|
`setGear` 应是一个声明函数。
|
||||||
|
@ -28,7 +28,7 @@ assert.typeOf(squareList, 'function'),
|
|||||||
不应该使用 `for`、`while` 或者 `forEach`。
|
不应该使用 `for`、`while` 或者 `forEach`。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
assert(!code.match(/for|while|forEach/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
应该使用 `map`、`filter` 或者 `reduce`。
|
应该使用 `map`、`filter` 或者 `reduce`。
|
||||||
@ -36,7 +36,7 @@ assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
|||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
.removeWhiteSpace(code)
|
||||||
.match(/\.(map|filter|reduce)\(/g)
|
.match(/\.(map|filter|reduce)\(/g)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
@ -52,7 +52,7 @@ assert(
|
|||||||
不能使用 `for` 循环。
|
不能使用 `for` 循环。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
|
assert(!code.match(/for\s*?\([\s\S]*?\)/));
|
||||||
```
|
```
|
||||||
|
|
||||||
你的代码应使用 `map` 方法。
|
你的代码应使用 `map` 方法。
|
||||||
|
@ -49,9 +49,7 @@ You should not copy and return the array.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/
|
/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -65,7 +65,7 @@ assert.deepEqual(copyMachine(['it works'], 3), [
|
|||||||
The `copyMachine` function should utilize the `spread operator` with array `arr`
|
The `copyMachine` function should utilize the `spread operator` with array `arr`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(__helpers.removeJSComments(code).match(/\.\.\.arr/));
|
assert(code.match(/\.\.\.arr/));
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
id: bd7123c9c441eddfaeb4bdef
|
id: bd7123c9c441eddfaeb4bdef
|
||||||
title: Comment Your JavaScript Code
|
title: Comment Your JavaScript Code
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
|
removeComments: false
|
||||||
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
||||||
forumTopicId: 16783
|
forumTopicId: 16783
|
||||||
dashedName: comment-your-javascript-code
|
dashedName: comment-your-javascript-code
|
||||||
|
@ -45,7 +45,7 @@ You should add a local `myVar` variable.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(
|
/functionmyLocalScope\(\)\{.*(var|let|const)myVar[\s\S]*}/.test(
|
||||||
__helpers.removeWhiteSpace(code)
|
__helpers.removeWhiteSpace(code)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -66,9 +66,7 @@ Your code should not rely on any kind of loops (`for` or `while` or higher order
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ You should use recursion to solve this problem.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1
|
sum.toString().match(/sum\(.*\)/g).length > 1
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -59,9 +59,7 @@ Your code should not rely on any kind of loops (`for`, `while` or higher order f
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ You should use recursion to solve this problem.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/)
|
countdown.toString().match(/countdown\s*\(.+\)/)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -26,9 +26,7 @@ Your code should not use any loop syntax (`for` or `while` or higher order funct
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -36,9 +34,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
rangeOfNumbers.toString().match(/rangeOfNumbers\s*\(.+\)/)
|
||||||
.removeJSComments(rangeOfNumbers.toString())
|
|
||||||
.match(/rangeOfNumbers\s*\(.+\)/)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ You should use `console.clear()` to clear the browser console.
|
|||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
.removeWhiteSpace(code)
|
||||||
.match(/console.clear\(\)/)
|
.match(/console.clear\(\)/)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
@ -32,11 +32,7 @@ Make the promise handle success and failure. If `responseFromServer` is `true`,
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -44,11 +40,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -43,9 +43,7 @@ You should remove the ES5 assignment syntax.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -53,11 +51,7 @@ You should use destructuring to create the `today` variable.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -65,11 +59,7 @@ You should use destructuring to create the `tomorrow` variable.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ Refactor the function `setGear` inside the object `bicycle` to use the shorthand
|
|||||||
Traditional function expression should not be used.
|
Traditional function expression should not be used.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
(getUserInput) => assert(!__helpers.removeJSComments(code).match(/function/));
|
(getUserInput) => assert(!code.match(/function/));
|
||||||
```
|
```
|
||||||
|
|
||||||
`setGear` should be a declarative function.
|
`setGear` should be a declarative function.
|
||||||
|
@ -28,7 +28,7 @@ assert.typeOf(squareList, 'function'),
|
|||||||
`for`, `while`, and `forEach` should not be used.
|
`for`, `while`, and `forEach` should not be used.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
assert(!code.match(/for|while|forEach/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
`map`, `filter`, or `reduce` should be used.
|
`map`, `filter`, or `reduce` should be used.
|
||||||
@ -36,7 +36,7 @@ assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
|||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
.removeWhiteSpace(code)
|
||||||
.match(/\.(map|filter|reduce)\(/g)
|
.match(/\.(map|filter|reduce)\(/g)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
@ -52,7 +52,7 @@ assert(
|
|||||||
Your code should not use a `for` loop.
|
Your code should not use a `for` loop.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
|
assert(!code.match(/for\s*?\([\s\S]*?\)/));
|
||||||
```
|
```
|
||||||
|
|
||||||
Your code should use the `map` method.
|
Your code should use the `map` method.
|
||||||
|
@ -49,11 +49,7 @@ You should not copy and return the array.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ assert.deepEqual(copyMachine(['it works'], 3), [
|
|||||||
La función `copyMachine` debe utilizar el `spread operator` (operador de propagación) con el arreglo `arr`
|
La función `copyMachine` debe utilizar el `spread operator` (operador de propagación) con el arreglo `arr`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(__helpers.removeJSComments(code).match(/\.\.\.arr/));
|
assert(code.match(/\.\.\.arr/));
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
|
@ -3,6 +3,7 @@ id: bd7123c9c441eddfaeb4bdef
|
|||||||
title: Comenta tu código de JavaScript
|
title: Comenta tu código de JavaScript
|
||||||
challengeType: 1
|
challengeType: 1
|
||||||
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
videoUrl: 'https://scrimba.com/c/c7ynnTp'
|
||||||
|
removeComments: false
|
||||||
forumTopicId: 16783
|
forumTopicId: 16783
|
||||||
dashedName: comment-your-javascript-code
|
dashedName: comment-your-javascript-code
|
||||||
---
|
---
|
||||||
|
@ -45,7 +45,7 @@ Debes agregar una variable local `myVar`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(
|
/functionmyLocalScope\(\)\{.*(var|let|const)myVar[\s\S]*}/.test(
|
||||||
__helpers.removeWhiteSpace(code)
|
__helpers.removeWhiteSpace(code)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -66,9 +66,7 @@ Tu código no debe depender de ningún tipo de bluces (`for` o `while`) o funcio
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ Debes usar recursión para resolver este problema.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1
|
sum.toString().match(/sum\(.*\)/g).length > 1
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -59,9 +59,7 @@ Tu código no debe depender de ningún tipo de bucles (`for`, `while` o funcione
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ Debes usar recursión para resolver este problema.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers.removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/)
|
countdown.toString().match(/countdown\s*\(.+\)/)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -26,9 +26,7 @@ Tu código no debe utilizar bucles (`for`, `while` o funciones de orden superior
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/for|while|forEach|map|filter|reduce/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/for|while|forEach|map|filter|reduce/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -36,9 +34,7 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
rangeOfNumbers.toString().match(/rangeOfNumbers\s*\(.+\)/)
|
||||||
.removeJSComments(rangeOfNumbers.toString())
|
|
||||||
.match(/rangeOfNumbers\s*\(.+\)/)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ Debes utilizar `console.clear()` para limpiar la consola del navegador.
|
|||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
.removeWhiteSpace(code)
|
||||||
.match(/console.clear\(\)/)
|
.match(/console.clear\(\)/)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
@ -32,11 +32,9 @@ Haz una función promesa que maneje el éxito y el fallo. Si `responseFromServer
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g
|
/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -44,11 +42,9 @@ assert(
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
|
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -43,9 +43,7 @@ Debes eliminar la sintaxis de asignación ES5.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
||||||
.removeJSComments(code)
|
|
||||||
.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
|
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -53,11 +51,9 @@ Debes usar desestructuración para crear la variable `today`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -65,11 +61,9 @@ Debes usar desestructuración para crear la variable `tomorrow`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ Refactoriza la función `setGear` dentro del objeto `bicycle` para que utilice l
|
|||||||
La expresión tradicional "function" no debe ser utilizada.
|
La expresión tradicional "function" no debe ser utilizada.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
(getUserInput) => assert(!__helpers.removeJSComments(code).match(/function/));
|
(getUserInput) => assert(!code.match(/function/));
|
||||||
```
|
```
|
||||||
|
|
||||||
`setGear` debe ser una función declarativa.
|
`setGear` debe ser una función declarativa.
|
||||||
|
@ -28,7 +28,7 @@ assert.typeOf(squareList, 'function'),
|
|||||||
`for`, `while`, y `forEach` no deben ser usados.
|
`for`, `while`, y `forEach` no deben ser usados.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
assert(!code.match(/for|while|forEach/g));
|
||||||
```
|
```
|
||||||
|
|
||||||
`map`, `filter`, o `reduce` deben ser usados.
|
`map`, `filter`, o `reduce` deben ser usados.
|
||||||
@ -36,7 +36,7 @@ assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
|||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
__helpers
|
__helpers
|
||||||
.removeWhiteSpace(__helpers.removeJSComments(code))
|
.removeWhiteSpace(code)
|
||||||
.match(/\.(map|filter|reduce)\(/g)
|
.match(/\.(map|filter|reduce)\(/g)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
@ -52,7 +52,7 @@ assert(
|
|||||||
Tu código no debe usar un bucle `for`.
|
Tu código no debe usar un bucle `for`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(!__helpers.removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
|
assert(!code.match(/for\s*?\([\s\S]*?\)/));
|
||||||
```
|
```
|
||||||
|
|
||||||
Tu código debe usar el método `map`.
|
Tu código debe usar el método `map`.
|
||||||
|
@ -49,11 +49,9 @@ You should not copy and return the array.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
assert(
|
assert(
|
||||||
!__helpers
|
!code.match(
|
||||||
.removeJSComments(code)
|
|
||||||
.match(
|
|
||||||
/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/
|
/(1430952867)|(1460357289)|(1406357289)|(4130952867)|(4160357289)|(4106357289)/
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ const schema = Joi.object()
|
|||||||
block: Joi.string().regex(slugRE),
|
block: Joi.string().regex(slugRE),
|
||||||
blockId: Joi.objectId(),
|
blockId: Joi.objectId(),
|
||||||
challengeOrder: Joi.number(),
|
challengeOrder: Joi.number(),
|
||||||
|
removeComments: Joi.bool(),
|
||||||
challengeType: Joi.number().min(0).max(11).required(),
|
challengeType: Joi.number().min(0).max(11).required(),
|
||||||
checksum: Joi.number(),
|
checksum: Joi.number(),
|
||||||
// __commentCounts is only used to test the comment replacement
|
// __commentCounts is only used to test the comment replacement
|
||||||
|
@ -520,11 +520,17 @@ async function createTestRunner(
|
|||||||
files[key].editableContents = solution[key].editableContents;
|
files[key].editableContents = solution[key].editableContents;
|
||||||
});
|
});
|
||||||
|
|
||||||
const { build, sources, loadEnzyme } = await buildChallenge({
|
const { build, sources, loadEnzyme } = await buildChallenge(
|
||||||
files,
|
{
|
||||||
required,
|
files,
|
||||||
template
|
required,
|
||||||
});
|
template
|
||||||
|
},
|
||||||
|
{
|
||||||
|
removeComments: challenge.removeComments
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const code = {
|
const code = {
|
||||||
contents: sources.index,
|
contents: sources.index,
|
||||||
editableContents: sources.editableContents
|
editableContents: sources.editableContents
|
||||||
|
Reference in New Issue
Block a user