From 275eab2a9ddb80de9dd25407a7d8f63e3030a805 Mon Sep 17 00:00:00 2001 From: Sarthak Bansal Date: Sun, 2 Aug 2026 16:26:46 +0530 Subject: [PATCH] refactor(curriculum): replace greeting bot regex tests with helpers (#69132) --- .../workshop-greeting-bot/66ad8294a0ad902f1b31b612.md | 9 +++++++-- .../workshop-greeting-bot/66ad8ab945d266383f318cbf.md | 10 ++++++++-- .../workshop-greeting-bot/66ad8d150264db3926eccfeb.md | 4 +++- .../workshop-greeting-bot/66ad9c633fa26d3c1475eae3.md | 10 ++++++++-- .../workshop-greeting-bot/66ada3f46945763dd97f43f8.md | 8 +++++++- .../workshop-greeting-bot/66adb844118ba74107ce771f.md | 8 +++++++- .../workshop-greeting-bot/66adc42868cab843ccee87d9.md | 8 +++++++- .../workshop-greeting-bot/66adc6046acc18453decf577.md | 8 +++++++- .../workshop-greeting-bot/66adcf383276814776aba3ca.md | 8 +++++++- .../workshop-greeting-bot/66add47d27763c4862492c8c.md | 11 ++++++++--- 10 files changed, 69 insertions(+), 15 deletions(-) diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8294a0ad902f1b31b612.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8294a0ad902f1b31b612.md index 65460303a8c..28980cc2884 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8294a0ad902f1b31b612.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8294a0ad902f1b31b612.md @@ -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-- diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8ab945d266383f318cbf.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8ab945d266383f318cbf.md index 31bdb8ce90e..8c0c27cd538 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8ab945d266383f318cbf.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8ab945d266383f318cbf.md @@ -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-- diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8d150264db3926eccfeb.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8d150264db3926eccfeb.md index c934d8c7216..6765ef7d718 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8d150264db3926eccfeb.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad8d150264db3926eccfeb.md @@ -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-- diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad9c633fa26d3c1475eae3.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad9c633fa26d3c1475eae3.md index 6297da64328..2445e9c083a 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad9c633fa26d3c1475eae3.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ad9c633fa26d3c1475eae3.md @@ -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-- diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ada3f46945763dd97f43f8.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ada3f46945763dd97f43f8.md index a7b5717799e..1016c6d8bcc 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66ada3f46945763dd97f43f8.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66ada3f46945763dd97f43f8.md @@ -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. diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adb844118ba74107ce771f.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adb844118ba74107ce771f.md index ef82f1f8558..367fcb8d22e 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adb844118ba74107ce771f.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adb844118ba74107ce771f.md @@ -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. diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc42868cab843ccee87d9.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc42868cab843ccee87d9.md index f97a95c6902..0774f7653f8 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc42868cab843ccee87d9.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc42868cab843ccee87d9.md @@ -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. diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc6046acc18453decf577.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc6046acc18453decf577.md index 5a7dc14d914..63ee22a5fa4 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc6046acc18453decf577.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adc6046acc18453decf577.md @@ -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. diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adcf383276814776aba3ca.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adcf383276814776aba3ca.md index 2c12911d167..541455db078 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66adcf383276814776aba3ca.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66adcf383276814776aba3ca.md @@ -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. diff --git a/curriculum/challenges/english/blocks/workshop-greeting-bot/66add47d27763c4862492c8c.md b/curriculum/challenges/english/blocks/workshop-greeting-bot/66add47d27763c4862492c8c.md index 8b62a2ec35f..4d64155b10b 100644 --- a/curriculum/challenges/english/blocks/workshop-greeting-bot/66add47d27763c4862492c8c.md +++ b/curriculum/challenges/english/blocks/workshop-greeting-bot/66add47d27763c4862492c8c.md @@ -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--