refactor(curriculum): replace greeting bot regex tests with helpers (#69132)

This commit is contained in:
Sarthak Bansal
2026-08-02 16:26:46 +05:30
committed by GitHub
parent 45b5c1e26d
commit 275eab2a9d
10 changed files with 69 additions and 15 deletions
@@ -21,19 +21,24 @@ console.log("Hello, World!");
Add a `console.log()` statement that outputs the string `"Hi there!"` to the console. Don't forget your quotes around the message!
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a `console.log()` statement in your code.
```js
assert.match(__helpers.removeJSComments(code), /console\.log(.*)/);
assert.isNotEmpty(logSpy.calls);
```
Your `console` statement should have the message `"Hi there!"`. Don't forget the quotes.
```js
assert.match(__helpers.removeJSComments(code), /console\.log\((['"])Hi\s+there!\1\);?/);
assert.deepInclude(logSpy.calls, ["Hi there!"]);
```
# --seed--
@@ -13,18 +13,24 @@ It is time to add a second message from the bot.
Add another `console.log` statement to output the message `"I am excited to talk to you."` to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a second `console.log()` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 2);
assert.lengthOf(logSpy.calls, 2);
```
Your `console` statement should have the message `"I am excited to talk to you."`. Don't forget the quotes.
```js
assert.match(__helpers.removeJSComments(code), /("|')I\s+am\s+excited\s+to\s+talk\s+to\s+you.\1/);
assert.deepInclude(logSpy.calls, ["I am excited to talk to you."]);
```
# --seed--
@@ -36,7 +36,9 @@ assert.isNotNull(bot);
You should use the `let` keyword to declare the variable.
```js
assert.match(__helpers.removeJSComments(code), /let\s+bot;?/g);
const explorer = await __helpers.Explorer(code);
const { bot } = explorer.variables;
assert.isTrue(bot?.matches('let bot'));
```
# --seed--
@@ -11,18 +11,24 @@ Now, it is time to add another message from the bot.
Add another `console` statement to the code that logs the message `"Allow me to introduce myself."`.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a third `console.log()` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 3);
assert.lengthOf(logSpy.calls, 3);
```
Your `console` statement should have the message `"Allow me to introduce myself."`. Don't forget the quotes.
```js
assert.match(__helpers.removeJSComments(code), /("|')Allow\s+me\s+to\s+introduce\s+myself.\1/);
assert.deepInclude(logSpy.calls, ["Allow me to introduce myself."]);
```
# --seed--
@@ -28,6 +28,12 @@ Assign this value to the `botIntroduction` variable.
Then, log the `botIntroduction` variable to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a variable called `botIntroduction`.
@@ -51,7 +57,7 @@ assert.equal(botIntroduction, "My name is teacherBot.");
You should have a fourth `console.log()` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 4);
assert.lengthOf(logSpy.calls, 4);
```
Your `console` statement should output the `botIntroduction` variable.
@@ -17,6 +17,12 @@ Assign this value to the `botLocationSentence` variable.
Then, log the value of `botLocationSentence` to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a `botLocationSentence` variable.
@@ -40,7 +46,7 @@ assert.equal(botLocationSentence, "I live in the universe.");
You should have a `console` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 5);
assert.lengthOf(logSpy.calls, 5);
```
Your `console` statement should output the `botLocationSentence` variable.
@@ -17,6 +17,12 @@ Assign the resulting string to the `nicknameIntroduction` variable.
Then, log the value of `nicknameIntroduction` to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a variable called `nicknameIntroduction`.
@@ -40,7 +46,7 @@ assert.strictEqual(nicknameIntroduction, "My nickname is professorBot.");
You should have a `console` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 6);
assert.lengthOf(logSpy.calls, 6);
```
You should log the value of `nicknameIntroduction` to the console.
@@ -17,6 +17,12 @@ Assign the result to the `newNicknameGreeting` variable.
Then, log the value of `newNicknameGreeting` to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a variable called `newNicknameGreeting`.
@@ -40,7 +46,7 @@ assert.strictEqual(newNicknameGreeting, "I love my nickname but I wish people wo
You should have a `console` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 7);
assert.lengthOf(logSpy.calls, 7);
```
You should log the value of `newNicknameGreeting` to the console.
@@ -15,6 +15,12 @@ Assign the result to the `favoriteSubjectSentence` variable.
Then, log the value of `favoriteSubjectSentence` to the console.
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a variable called `favoriteSubjectSentence`.
@@ -38,7 +44,7 @@ assert.strictEqual(favoriteSubjectSentence, "My favorite subject is Computer Sci
You should have a `console` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 8);
assert.lengthOf(logSpy.calls, 8);
```
You should log the value of `favoriteSubjectSentence` to the console.
@@ -11,19 +11,24 @@ For the final step, you will log the bot's message of `"Well, it was nice to tal
And with that, your greeting bot is complete!
# --before-each--
```js
const logSpy = __helpers.spyOn(console, 'log');
```
# --hints--
You should have a `console` statement in your code.
```js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log(.*)/g), 9);
assert.lengthOf(logSpy.calls, 9);
```
Your `console` statement should log the string `"Well, it was nice to talk to you. Have a nice day!"`.
```js
assert.match(__helpers.removeJSComments(code), /console\.log\s*\(\s*["']Well\s*,\s*it\s*was\s*nice\s*to\s*talk\s*to\s*you\s*\.\s*Have\s*a\s*nice\s*day\s*!["']\s*\)\s*/
);
assert.deepInclude(logSpy.calls, ["Well, it was nice to talk to you. Have a nice day!"]);
```
# --seed--