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:
Evgeny Klimenchenko
2021-04-28 16:18:54 +01:00
committed by GitHub
parent ebe8f99345
commit db369fbed1
47 changed files with 103 additions and 149 deletions

View File

@ -65,7 +65,7 @@ assert.deepEqual(copyMachine(['it works'], 3), [
`copyMachine` 函数中应对 `arr` 使用展开运算符(`spread operator`)。
```js
assert(__helpers.removeJSComments(code).match(/\.\.\.arr/));
assert(code.match(/\.\.\.arr/));
```
# --seed--

View File

@ -3,6 +3,7 @@ id: bd7123c9c441eddfaeb4bdef
title: 给代码添加注释
challengeType: 1
videoUrl: 'https://scrimba.com/c/c7ynnTp'
removeComments: false
forumTopicId: 16783
dashedName: comment-your-javascript-code
---

View File

@ -45,7 +45,7 @@ assert.throws(declared, ReferenceError);
```js
assert(
/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(
/functionmyLocalScope\(\)\{.*(var|let|const)myVar[\s\S]*}/.test(
__helpers.removeWhiteSpace(code)
)
);

View File

@ -66,9 +66,7 @@ assert.equal(sum([2, 3, 4, 5], 3), 9);
```js
assert(
!__helpers
.removeJSComments(code)
.match(/for|while|forEach|map|filter|reduce/g)
!code.match(/for|while|forEach|map|filter|reduce/g)
);
```
@ -76,7 +74,7 @@ assert(
```js
assert(
__helpers.removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1
sum.toString().match(/sum\(.*\)/g).length > 1
);
```

View File

@ -59,9 +59,7 @@ assert.deepStrictEqual(countdown(5), [5, 4, 3, 2, 1]);
```js
assert(
!__helpers
.removeJSComments(code)
.match(/for|while|forEach|map|filter|reduce/g)
!code.match(/for|while|forEach|map|filter|reduce/g)
);
```
@ -69,7 +67,7 @@ assert(
```js
assert(
__helpers.removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/)
countdown.toString().match(/countdown\s*\(.+\)/)
);
```

View File

@ -26,9 +26,7 @@ assert(Array.isArray(rangeOfNumbers(5, 10)));
```js
assert(
!__helpers
.removeJSComments(code)
.match(/for|while|forEach|map|filter|reduce/g)
!code.match(/for|while|forEach|map|filter|reduce/g)
);
```
@ -36,9 +34,7 @@ assert(
```js
assert(
__helpers
.removeJSComments(rangeOfNumbers.toString())
.match(/rangeOfNumbers\s*\(.+\)/)
rangeOfNumbers.toString().match(/rangeOfNumbers\s*\(.+\)/)
);
```

View File

@ -32,9 +32,7 @@ dashedName: understanding-the-differences-between-the-freecodecamp-and-browser-c
```js
assert(
__helpers
.removeWhiteSpace(__helpers.removeJSComments(code))
.match(/console.clear\(\)/)
__helpers.removeWhiteSpace(code).match(/console.clear\(\)/)
);
```

View File

@ -32,9 +32,7 @@ const myPromise = new Promise((resolve, reject) => {
```js
assert(
__helpers
.removeJSComments(code)
.match(
code.match(
/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
assert(
__helpers
.removeJSComments(code)
.match(
code.match(
/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g
)
);

View File

@ -43,9 +43,7 @@ const { name, age } = user;
```js
assert(
!__helpers
.removeJSComments(code)
.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
!code.match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)
);
```
@ -53,9 +51,7 @@ assert(
```js
assert(
__helpers
.removeJSComments(code)
.match(
code.match(
/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
)
);
@ -65,9 +61,7 @@ assert(
```js
assert(
__helpers
.removeJSComments(code)
.match(
code.match(
/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g
)
);

View File

@ -39,7 +39,7 @@ const person = {
不应使用传统的函数定义方法。
```js
(getUserInput) => assert(!__helpers.removeJSComments(code).match(/function/));
(getUserInput) => assert(!code.match(/function/));
```
`setGear` 应是一个声明函数。

View File

@ -28,7 +28,7 @@ assert.typeOf(squareList, 'function'),
不应该使用 `for``while` 或者 `forEach`
```js
assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
assert(!code.match(/for|while|forEach/g));
```
应该使用 `map``filter` 或者 `reduce`
@ -36,7 +36,7 @@ assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
```js
assert(
__helpers
.removeWhiteSpace(__helpers.removeJSComments(code))
.removeWhiteSpace(code)
.match(/\.(map|filter|reduce)\(/g)
);
```

View File

@ -52,7 +52,7 @@ assert(
不能使用 `for` 循环。
```js
assert(!__helpers.removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
assert(!code.match(/for\s*?\([\s\S]*?\)/));
```
你的代码应使用 `map` 方法。