mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(tools,client): remove head and tail logic (#66524)
This commit is contained in:
@@ -10,11 +10,9 @@ const props = {
|
||||
contents: '',
|
||||
editableRegionBoundaries: [0, 2],
|
||||
ext: 'html',
|
||||
head: '',
|
||||
id: '',
|
||||
key: 'indexhtml',
|
||||
name: 'index',
|
||||
tail: ''
|
||||
name: 'index'
|
||||
}
|
||||
],
|
||||
stepNum: 5,
|
||||
|
||||
@@ -33,8 +33,6 @@ export interface ChallengeSeed {
|
||||
contents: string;
|
||||
ext: string;
|
||||
editableRegionBoundaries: number[];
|
||||
head?: string;
|
||||
tail?: string;
|
||||
}
|
||||
|
||||
// Build the base markdown for a step
|
||||
@@ -56,20 +54,8 @@ function getStepTemplate({
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
const seedHeads = challengeSeeds
|
||||
.filter(({ head }) => head)
|
||||
.map(({ ext, head }) => getCodeBlock(ext, head))
|
||||
.join('\n');
|
||||
|
||||
const seedTails = challengeSeeds
|
||||
.filter(({ tail }) => tail)
|
||||
.map(({ ext, tail }) => getCodeBlock(ext, tail))
|
||||
.join('\n');
|
||||
|
||||
const stepDescription = `step ${stepNum} instructions`;
|
||||
const seedChallengeSection = getSeedSection(seedTexts, 'seed-contents');
|
||||
const seedHeadSection = getSeedSection(seedHeads, 'before-user-code');
|
||||
const seedTailSection = getSeedSection(seedTails, 'after-user-code');
|
||||
|
||||
const demoString = isFirstChallenge
|
||||
? `
|
||||
@@ -99,10 +85,7 @@ ${stepDescription}
|
||||
Test 1
|
||||
|
||||
${getCodeBlock('js')}
|
||||
# --seed--` +
|
||||
seedChallengeSection +
|
||||
seedHeadSection +
|
||||
seedTailSection
|
||||
# --seed--` + seedChallengeSection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +65,6 @@ assert(
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```js
|
||||
// this runs before the user's code is evaluated.
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: white;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
@@ -1,17 +1,5 @@
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
@@ -31,20 +19,6 @@ body {
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: white;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
@@ -1,32 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --before-all--
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
@@ -1,96 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: white;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
@@ -39,31 +39,7 @@ if(let x of xs) {
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
This section intentionally has no `## --seed-contents--`.
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: white;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
@@ -1,104 +0,0 @@
|
||||
# --description--
|
||||
|
||||
Paragraph 1
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
Third *hint* with <code>code</code> and `inline code`
|
||||
|
||||
```js
|
||||
// more test code
|
||||
if(let x of xs) {
|
||||
console.log(x);
|
||||
}
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
::id{#html-key}
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: white;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
@@ -1,17 +1,5 @@
|
||||
# --seed--
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
etc: ''
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- comment -->
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
@@ -31,20 +19,6 @@ body {
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```css
|
||||
body {
|
||||
background: blue;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# --solutions--
|
||||
|
||||
|
||||
@@ -27,17 +27,3 @@ const Button = () => {
|
||||
return <button> {/* another comment! */} text </button>;
|
||||
};
|
||||
```
|
||||
|
||||
## --before-user-code--
|
||||
|
||||
```jsx
|
||||
function setup() {}
|
||||
```
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```jsx
|
||||
function teardown(params) {
|
||||
// after
|
||||
}
|
||||
```
|
||||
|
||||
@@ -11,10 +11,8 @@ exports[`challenge parser > should import md from other files 1`] = `
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -22,10 +20,8 @@ exports[`challenge parser > should import md from other files 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';
|
||||
@@ -35,10 +31,8 @@ for (let index = 0; index < array.length; index++) {
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "custom-name",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"description": "<section id="description">
|
||||
@@ -76,10 +70,8 @@ exports[`challenge parser > should not mix other YAML with the frontmatter 1`] =
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -87,19 +79,15 @@ exports[`challenge parser > should not mix other YAML with the frontmatter 1`] =
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"description": "<section id="description">
|
||||
@@ -183,10 +171,8 @@ exports[`challenge parser > should parse a more realistic md file 1`] = `
|
||||
23,
|
||||
],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "html-key",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -206,19 +192,15 @@ a {
|
||||
9,
|
||||
],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": " // this runs before the user's code is evaluated.",
|
||||
"id": "final-key",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"description": "<section id="description">
|
||||
@@ -265,10 +247,8 @@ a {
|
||||
</body>
|
||||
</html>",
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "html-key",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -284,18 +264,14 @@ a {
|
||||
color: green;
|
||||
}",
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "final-key",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
],
|
||||
@@ -349,10 +325,8 @@ exports[`challenge parser > should parse a simple md file 1`] = `
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -360,19 +334,15 @@ exports[`challenge parser > should parse a simple md file 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "{
|
||||
@@ -382,10 +352,8 @@ exports[`challenge parser > should parse a simple md file 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "json",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "tsconfig",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"description": "<section id="description">
|
||||
@@ -406,28 +374,22 @@ exports[`challenge parser > should parse a simple md file 1`] = `
|
||||
</body>
|
||||
</html>",
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "html-key",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
background: white;
|
||||
}",
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
],
|
||||
@@ -462,10 +424,8 @@ exports[`challenge parser > should parse frontmatter 1`] = `
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -473,19 +433,15 @@ exports[`challenge parser > should parse frontmatter 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"challengeType": 0,
|
||||
@@ -524,10 +480,8 @@ exports[`challenge parser > should parse gfm strikethrough and frontmatter 1`] =
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -535,19 +489,15 @@ exports[`challenge parser > should parse gfm strikethrough and frontmatter 1`] =
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
"description": "<section id="description">
|
||||
@@ -582,28 +532,22 @@ exports[`challenge parser > should parse gfm strikethrough and frontmatter 1`] =
|
||||
</body>
|
||||
</html>",
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "html-key",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
background: white;
|
||||
}",
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
-2
@@ -6,8 +6,6 @@ type ChallengeFile = {
|
||||
contents: string;
|
||||
ext: string;
|
||||
editableRegionBoundaries: number[];
|
||||
head?: string;
|
||||
tail?: string;
|
||||
};
|
||||
export interface ParsedChallenge {
|
||||
id: string;
|
||||
|
||||
@@ -10,10 +10,8 @@ exports[`add-seed plugin > should have an output to match the snapshot 1`] = `
|
||||
</html>",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
@@ -21,19 +19,15 @@ exports[`add-seed plugin > should have an output to match the snapshot 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "{
|
||||
@@ -43,10 +37,8 @@ exports[`add-seed plugin > should have an output to match the snapshot 1`] = `
|
||||
}",
|
||||
"editableRegionBoundaries": [],
|
||||
"ext": "json",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "tsconfig",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -10,28 +10,22 @@ exports[`add solution plugin > should have an output to match the snapshot 1`] =
|
||||
</body>
|
||||
</html>",
|
||||
"ext": "html",
|
||||
"head": "",
|
||||
"id": "html-key",
|
||||
"name": "index",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "body {
|
||||
background: white;
|
||||
}",
|
||||
"ext": "css",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "styles",
|
||||
"tail": "",
|
||||
},
|
||||
{
|
||||
"contents": "var x = 'y';",
|
||||
"ext": "js",
|
||||
"head": "",
|
||||
"id": "",
|
||||
"name": "script",
|
||||
"tail": "",
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
@@ -38,22 +38,17 @@ function addSeeds() {
|
||||
// processing in these cases.
|
||||
if (isEmpty(seedTree.children)) return;
|
||||
const contentsTree = root(getSection(seedTree, `--seed-contents--`));
|
||||
const headTree = root(getSection(seedTree, `--before-user-code--`));
|
||||
const tailTree = root(getSection(seedTree, `--after-user-code--`));
|
||||
const seeds = {};
|
||||
|
||||
// While before and after code are optional, the contents are not
|
||||
// Seed contents are required.
|
||||
if (isEmpty(contentsTree.children))
|
||||
throw Error('## --seed-contents-- must appear in # --seed-- sections');
|
||||
|
||||
const visitForContents = visitChildren(
|
||||
getFileVisitor(seeds, 'contents', validateEditableMarkers)
|
||||
);
|
||||
const visitForHead = visitChildren(getFileVisitor(seeds, 'head'));
|
||||
const visitForTail = visitChildren(getFileVisitor(seeds, 'tail'));
|
||||
visitForContents(contentsTree);
|
||||
visitForHead(headTree);
|
||||
visitForTail(tailTree);
|
||||
|
||||
const seedVals = Object.values(seeds);
|
||||
file.data = {
|
||||
...file.data,
|
||||
|
||||
@@ -7,14 +7,9 @@ import addSeed from './add-seed';
|
||||
describe('add-seed plugin', () => {
|
||||
let adjacentKeysAST,
|
||||
withSeedKeysAST,
|
||||
withBeforeAfterAST,
|
||||
cCodeAST,
|
||||
withErmsOnOneLineAST,
|
||||
withEmptyAfterAST,
|
||||
withEmptyBeforeAST,
|
||||
withEmptyContentsAST,
|
||||
withInvalidBeforeAST,
|
||||
withInvalidAfterAST,
|
||||
simpleAST,
|
||||
withEditableMarkersAST,
|
||||
withSeedKeysOrphanAST,
|
||||
@@ -27,16 +22,11 @@ describe('add-seed plugin', () => {
|
||||
beforeAll(async () => {
|
||||
adjacentKeysAST = await parseFixture('with-seed-keys-adjacent.md');
|
||||
withSeedKeysAST = await parseFixture('with-seed-keys.md');
|
||||
withBeforeAfterAST = await parseFixture('with-before-and-after.md');
|
||||
cCodeAST = await parseFixture('with-c-code.md');
|
||||
withErmsOnOneLineAST = await parseFixture(
|
||||
'with-editable-markers-on-one-line.md'
|
||||
);
|
||||
withEmptyAfterAST = await parseFixture('with-empty-after.md');
|
||||
withEmptyBeforeAST = await parseFixture('with-empty-before.md');
|
||||
withEmptyContentsAST = await parseFixture('with-empty-contents.md');
|
||||
withInvalidBeforeAST = await parseFixture('with-invalid-before.md');
|
||||
withInvalidAfterAST = await parseFixture('with-invalid-after.md');
|
||||
simpleAST = await parseFixture('simple.md');
|
||||
withEditableMarkersAST = await parseFixture('with-editable-markers.md');
|
||||
withSeedKeysOrphanAST = await parseFixture('with-seed-keys-orphan.md');
|
||||
@@ -65,23 +55,19 @@ describe('add-seed plugin', () => {
|
||||
});
|
||||
|
||||
it('adds test objects to the challengeFiles array following a schema', () => {
|
||||
expect.assertions(15);
|
||||
expect.assertions(11);
|
||||
plugin(simpleAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const testObject = challengeFiles.find(x => x.ext === 'js');
|
||||
expect(Object.keys(testObject).length).toEqual(7);
|
||||
expect(Object.keys(testObject).length).toEqual(5);
|
||||
expect(testObject).toHaveProperty('ext');
|
||||
expect(typeof testObject['ext']).toBe('string');
|
||||
expect(testObject).toHaveProperty('name');
|
||||
expect(typeof testObject['name']).toBe('string');
|
||||
expect(testObject).toHaveProperty('contents');
|
||||
expect(typeof testObject['contents']).toBe('string');
|
||||
expect(testObject).toHaveProperty('head');
|
||||
expect(typeof testObject['head']).toBe('string');
|
||||
expect(testObject).toHaveProperty('tail');
|
||||
expect(typeof testObject['tail']).toBe('string');
|
||||
expect(testObject).toHaveProperty('id');
|
||||
expect(typeof testObject['id']).toBe('string');
|
||||
expect(testObject).toHaveProperty('editableRegionBoundaries');
|
||||
@@ -155,96 +141,14 @@ describe('add-seed plugin', () => {
|
||||
expect(file).toEqual(fileTwo);
|
||||
});
|
||||
|
||||
it('gets the before-user-code for each language', () => {
|
||||
expect.assertions(3);
|
||||
plugin(withBeforeAfterAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const scriptjs = challengeFiles.find(x => x.ext === 'js');
|
||||
const indexhtml = challengeFiles.find(x => x.ext === 'html');
|
||||
const stylescss = challengeFiles.find(x => x.ext === 'css');
|
||||
|
||||
expect(scriptjs.head).toBe('');
|
||||
expect(indexhtml.head).toBe(`<!-- comment -->`);
|
||||
expect(stylescss.head).toBe(`body {
|
||||
etc: ''
|
||||
}`);
|
||||
});
|
||||
|
||||
it('gets the after-user-code for each language', () => {
|
||||
expect.assertions(3);
|
||||
plugin(withBeforeAfterAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const scriptjs = challengeFiles.find(x => x.ext === 'js');
|
||||
const indexhtml = challengeFiles.find(x => x.ext === 'html');
|
||||
const stylescss = challengeFiles.find(x => x.ext === 'css');
|
||||
|
||||
expect(scriptjs.tail).toBe(`function teardown(params) {
|
||||
// after
|
||||
}`);
|
||||
expect(indexhtml.tail).toBe('');
|
||||
expect(stylescss.tail).toBe(`body {
|
||||
background: blue;
|
||||
}`);
|
||||
});
|
||||
|
||||
it('throws an error if there is any code of an unsupported language', () => {
|
||||
expect.assertions(1);
|
||||
expect(() => plugin(cCodeAST, file)).toThrow(
|
||||
"On line 30 'c' is not a supported language.\n" +
|
||||
"On line 18 'c' is not a supported language.\n" +
|
||||
' Please use one of js, css, html, jsx, ts, tsx or py'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws if there is before/after code with empty blocks', () => {
|
||||
expect.assertions(2);
|
||||
expect(() => plugin(withInvalidBeforeAST, file)).toThrow(
|
||||
'Empty code block in --before-user-code-- section'
|
||||
);
|
||||
expect(() => plugin(withInvalidAfterAST, file)).toThrow(
|
||||
'Empty code block in --after-user-code-- section'
|
||||
);
|
||||
});
|
||||
|
||||
it('quietly ignores empty before sections', () => {
|
||||
expect.assertions(6);
|
||||
plugin(withEmptyBeforeAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const scriptjs = challengeFiles.find(x => x.ext === 'js');
|
||||
const indexhtml = challengeFiles.find(x => x.ext === 'html');
|
||||
const stylescss = challengeFiles.find(x => x.ext === 'css');
|
||||
|
||||
expect(scriptjs.head).toBe('');
|
||||
expect(scriptjs.tail).toBe('function teardown(params) {\n // after\n}');
|
||||
expect(indexhtml.head).toBe('');
|
||||
expect(indexhtml.tail).toBe('');
|
||||
expect(stylescss.head).toBe('');
|
||||
expect(stylescss.tail).toBe('body {\n background: blue;\n}');
|
||||
});
|
||||
|
||||
it('quietly ignores empty after sections', () => {
|
||||
expect.assertions(6);
|
||||
plugin(withEmptyAfterAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const scriptjs = challengeFiles.find(x => x.ext === 'js');
|
||||
const indexhtml = challengeFiles.find(x => x.ext === 'html');
|
||||
const stylescss = challengeFiles.find(x => x.ext === 'css');
|
||||
|
||||
expect(scriptjs.head).toBe('');
|
||||
expect(scriptjs.tail).toBe('');
|
||||
expect(indexhtml.head).toBe('<!-- comment -->');
|
||||
expect(indexhtml.tail).toBe('');
|
||||
expect(stylescss.head).toBe("body {\n etc: ''\n}");
|
||||
expect(stylescss.tail).toBe('');
|
||||
});
|
||||
|
||||
it('throws an error (with line number) if 2 markers appear on 1 line', () => {
|
||||
expect.assertions(1);
|
||||
expect(() => plugin(withErmsOnOneLineAST, file)).toThrow(
|
||||
@@ -253,17 +157,13 @@ describe('add-seed plugin', () => {
|
||||
});
|
||||
|
||||
it('handles jsx', () => {
|
||||
expect.assertions(3);
|
||||
expect.assertions(1);
|
||||
plugin(withSeedKeysJSXAST, file);
|
||||
const {
|
||||
data: { challengeFiles }
|
||||
} = file;
|
||||
const indexjsx = challengeFiles.find(x => x.ext === 'jsx');
|
||||
|
||||
expect(indexjsx.head).toBe(`function setup() {}`);
|
||||
expect(indexjsx.tail).toBe(`function teardown(params) {
|
||||
// after
|
||||
}`);
|
||||
expect(indexjsx.contents).toBe(`var x = 'y';
|
||||
|
||||
/* comment */
|
||||
|
||||
@@ -40,23 +40,19 @@ describe('add solution plugin', () => {
|
||||
});
|
||||
|
||||
it('adds solution objects to the challengeFiles array following a schema', () => {
|
||||
expect.assertions(13);
|
||||
expect.assertions(9);
|
||||
plugin(mockAST, file);
|
||||
const {
|
||||
data: { solutions }
|
||||
} = file;
|
||||
const testObject = solutions[0].find(solution => solution.ext === 'js');
|
||||
expect(Object.keys(testObject).length).toEqual(6);
|
||||
expect(Object.keys(testObject).length).toEqual(4);
|
||||
expect(testObject).toHaveProperty('ext');
|
||||
expect(typeof testObject['ext']).toBe('string');
|
||||
expect(testObject).toHaveProperty('name');
|
||||
expect(typeof testObject['name']).toBe('string');
|
||||
expect(testObject).toHaveProperty('contents');
|
||||
expect(typeof testObject['contents']).toBe('string');
|
||||
expect(testObject).toHaveProperty('head');
|
||||
expect(typeof testObject['head']).toBe('string');
|
||||
expect(testObject).toHaveProperty('tail');
|
||||
expect(typeof testObject['tail']).toBe('string');
|
||||
expect(testObject).toHaveProperty('id');
|
||||
expect(typeof testObject['id']).toBe('string');
|
||||
});
|
||||
|
||||
@@ -4,10 +4,6 @@ const position = require('unist-util-position');
|
||||
|
||||
const getId = require('./get-id');
|
||||
|
||||
const keyToSection = {
|
||||
head: 'before-user-code',
|
||||
tail: 'after-user-code'
|
||||
};
|
||||
const supportedLanguages = [
|
||||
'js',
|
||||
'css',
|
||||
@@ -29,8 +25,6 @@ function defaultFile(lang, id) {
|
||||
ext: lang,
|
||||
name: getFilenames(lang),
|
||||
contents: '',
|
||||
head: '',
|
||||
tail: '',
|
||||
id
|
||||
};
|
||||
}
|
||||
@@ -74,11 +68,6 @@ function codeToData(node, seeds, seedKey, validate) {
|
||||
if (!seeds[fileId]) {
|
||||
seeds[fileId] = defaultFile(shortLang, id);
|
||||
}
|
||||
if (isEmpty(node.value) && seedKey !== 'contents') {
|
||||
const section = keyToSection[seedKey];
|
||||
throw Error(`Empty code block in --${section}-- section`);
|
||||
}
|
||||
|
||||
seeds[fileId][seedKey] = isEmpty(seeds[fileId][seedKey])
|
||||
? node.value
|
||||
: seeds[fileId][seedKey] + '\n' + node.value;
|
||||
|
||||
@@ -30,9 +30,6 @@ const VALID_MARKERS = [
|
||||
'## --sentence--',
|
||||
'## --text--',
|
||||
'## --video-solution--',
|
||||
// TODO: Remove these two markers when https://github.com/freeCodeCamp/freeCodeCamp/issues/57107 is resolved
|
||||
'## --after-user-code--',
|
||||
'## --before-user-code--',
|
||||
|
||||
// Level 3
|
||||
'### --audio-id--',
|
||||
|
||||
@@ -299,8 +299,6 @@ exports.createPagesStatefully = async function ({ graphql, actions }) {
|
||||
name
|
||||
ext
|
||||
contents
|
||||
head
|
||||
tail
|
||||
history
|
||||
fileKey
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user