From c3289cb66686792a618937478cceb876714bbf23 Mon Sep 17 00:00:00 2001 From: Dane Smith Date: Tue, 8 Oct 2024 10:04:32 -0500 Subject: [PATCH 1/3] Update test.js --- test/test.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index b720bef9..a4fa5639 100644 --- a/test/test.js +++ b/test/test.js @@ -2,6 +2,7 @@ * We have to do a bit of work upfront to allow the tests * to run in the browser and in Node.js. */ +const JSFILE = '../assignment/scripts/aboutMe.js' let assert, expect; let testItems = {}; if (typeof window === 'object') { @@ -31,13 +32,39 @@ if (typeof window === 'object') { // Run tests in Node.js assert = require('assert'); expect = require('chai').expect; - testItems = require('../assignment/scripts/aboutMe.js'); + testItems = require(JSFILE); } /** * Put all tests within this describe. */ describe('Automated tests', function () { + describe('Using let and const, not var', function () { + it(`Using let and const, not var`, function () { + + if (typeof window !== 'undefined') { + this.skip(); // Skip this test if running in a browser + } + + const fs = require('fs'); + const path = require('path') + // Read the file + fs.readFile(path.resolve(__dirname, JSFILE), 'utf8', (err, data) => { + if (err) { + console.error(err); + return; + } + + // Define the regex pattern + const regex = /var\s/g; + + // Find all matches + const matches = data.match(regex); + + expect(matches.length).to.equal(0); + }); + }) + }) describe(`First Name assigned to String`, function () { it(`First Name assigned to String`, function () { let { firstName } = testItems; From 8be8d02911104e8b24d8288141843fd75d20c616 Mon Sep 17 00:00:00 2001 From: Dane Smith Date: Tue, 8 Oct 2024 10:05:08 -0500 Subject: [PATCH 2/3] Update reporter.js --- test/reporter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/reporter.js b/test/reporter.js index 1828f9bb..8cea1d95 100644 --- a/test/reporter.js +++ b/test/reporter.js @@ -40,11 +40,11 @@ class MyReporter { `| OPTIONAL: Questions in HTML | - |`, `\x1b[0m` ); - console.log( - `\x1b[32m`, - `| Use of let/const, no use of var | - |`, - `\x1b[0m` - ); + // console.log( + // `\x1b[32m`, + // `| Use of let/const, no use of var | - |`, + // `\x1b[0m` + // ); console.log( `\x1b[32m`, `| Runs in browser without console errors | yes |`, @@ -63,4 +63,4 @@ class MyReporter { } } -module.exports = MyReporter; \ No newline at end of file +module.exports = MyReporter; From bcadca3c265ca01449ed6109d3358615f3dd4f25 Mon Sep 17 00:00:00 2001 From: Dane Smith Date: Tue, 8 Oct 2024 10:18:29 -0500 Subject: [PATCH 3/3] Update test.js --- test/test.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/test.js b/test/test.js index a4fa5639..8e4538fb 100644 --- a/test/test.js +++ b/test/test.js @@ -39,31 +39,30 @@ if (typeof window === 'object') { * Put all tests within this describe. */ describe('Automated tests', function () { - describe('Using let and const, not var', function () { - it(`Using let and const, not var`, function () { + describe('Using let and const, not var', function () { + it(`Using let and const, not var`, function () { if (typeof window !== 'undefined') { this.skip(); // Skip this test if running in a browser - } + } const fs = require('fs'); const path = require('path') // Read the file - fs.readFile(path.resolve(__dirname, JSFILE), 'utf8', (err, data) => { - if (err) { - console.error(err); - return; - } + const data = fs.readFileSync(path.resolve(__dirname, JSFILE), 'utf8') + // Define the regex pattern const regex = /var\s/g; // Find all matches - const matches = data.match(regex); + const matches = data.match(regex); expect(matches.length).to.equal(0); - }); + }) + }); + }) describe(`First Name assigned to String`, function () { it(`First Name assigned to String`, function () {