Skip to content

Commit

Permalink
Add TDD Style testing to core language stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcguff committed Dec 15, 2023
1 parent bcf6ae9 commit 038d14b
Show file tree
Hide file tree
Showing 10 changed files with 6,469 additions and 138 deletions.
79 changes: 19 additions & 60 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
**/.DS_Store
.DS_Store

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -22,48 +13,32 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
# Typescript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

Expand All @@ -73,40 +48,24 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/
# macOS files
.DS_Store
.AppleDouble
.LSOverride

# DynamoDB Local files
.dynamodb/
# Thumbnails
._*

# TernJS port file
.tern-port
# Files that might appear on external disks
.Spotlight-V100
.Trashes

# VSCode
.vscode
# Windows files
Thumbs.db
ehthumbs.db
Desktop.ini

# IntelliJ
.idea
# Visual Studio files
.vs
8 changes: 8 additions & 0 deletions conditional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


const getGreeting = (isMorning) => {
return isMorning ? "good Morning": "good Evening";
}

const result = getGreeting(true);
console.log(result);
35 changes: 35 additions & 0 deletions coreLanguageService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const coreLanguageService = {
printHelloWorld: () => {
console.log('Hello, world!');
},
printAllDataTypes: () => {
const myNumber = 42;
const myString = "Hello, world!";
const myBoolean = true;
const myUndefined = undefined;
const myNull = null;
const myObject = { foo: "bar" };
const mySymbol = Symbol("mySymbol");
const myBigInt = BigInt(9007199254740991);
console.log(
myNumber,
myString,
myBoolean,
myUndefined,
myNull,
myObject,
mySymbol,
myBigInt
);
},
getGreeting: (isMorning) => {
return isMorning ? "good Morning": "good Evening";
},
printLoop: () => {
for (let i = 1; i <= 10; i++) {
console.log(i);
}
}
}

module.exports = coreLanguageService;
65 changes: 0 additions & 65 deletions dataType.js

This file was deleted.

5 changes: 0 additions & 5 deletions function.js

This file was deleted.

4 changes: 0 additions & 4 deletions helloWorld.js

This file was deleted.

9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@


const coreLanguageService = require("./coreLanguageService");

(() => {
const result = 'message';
console.log(result);
coreLanguageService.printHelloWorld();
coreLanguageService.printAllDataTypes();
console.log(coreLanguageService.getGreeting(true));
coreLanguageService.printLoop();
})();
49 changes: 49 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

const service = require('./coreLanguageService');

describe('devguff-nodejs-language-core', () => {
describe("printHelloWorld", () => {
it("should print 'Hello, world!' to the console", () => {
const consoleLogMock = jest.fn();
console.log = consoleLogMock;
service.printHelloWorld();
expect(consoleLogMock).toHaveBeenCalledWith("Hello, world!");
});
});
describe("printAllDataTypes", () => {
it("should use all 8 data types in Node.js", () => {
const consoleLogMock = jest.fn();
console.log = consoleLogMock;
service.printAllDataTypes();
expect(consoleLogMock).toHaveBeenCalledWith(
42,
"Hello, world!",
true,
undefined,
null,
{ foo: "bar" },
expect.any(Symbol),
BigInt(9007199254740991)
);
});
});
describe("conditional", () => {
it("get greeting should return 'good Morning'", () => {
expect(service.getGreeting(true)).toBe("good Morning");
});
it("get greeting should return 'good Evening'", () => {
expect(service.getGreeting(false)).toBe("good Evening");
});
});
describe("printLoop", () => {
it("should print numbers 1 through 10 to the console", () => {
const consoleLogMock = jest.fn();
console.log = consoleLogMock;
service.printLoop();
for (let i = 1; i <= 10; i++) {
expect(consoleLogMock).nthCalledWith(i, i);
}
});
});
})

Loading

0 comments on commit 038d14b

Please sign in to comment.