Skip to content

Commit 96bcd10

Browse files
authored
Merge branch 'master' into master
2 parents 206b600 + 0655d71 commit 96bcd10

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ jobs:
1212
steps:
1313
- checkout
1414
- run: npm install
15+
- run: npm install node-fetch
1516
- run: npm test

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unit Testing and Continuous Integration
22

3+
[![CircleCI](https://circleci.com/gh/NHibiki-NYU/UnitTestingCI.svg?style=svg)](https://circleci.com/gh/NHibiki-NYU/UnitTestingCI)
4+
5+
To know how to use, please [Google](https://google.com)
6+
37
This repository is for sudents in the course to experiment with unit testing and continuous integration. It uses the testing framework [Jest](https://jestjs.io/) and [CircleCI](https://circleci.com/) as described in the video tutorials linked below.
48

59
This repo is forked from [CodingTrain/TestingTestTest](https://github.com/CodingTrain/TestingTestTest).

sketch.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function power(base, exponent) {
3737
return Math.pow(base, exponent);
3838
}
3939

40+
function nOfFibonacci(x) {
41+
let n = parseInt(x, 10);
42+
return (!n || n < 1) ? -1 : (n < 3 ? 1 : (nOfFibonacci(n-1) + nOfFibonacci(n-2)));
43+
}
44+
4045
module.exports = {
4146
sum: sum,
4247
sub: sub,
@@ -46,5 +51,6 @@ module.exports = {
4651
sayHelloTo: sayHelloTo,
4752
answer: answer,
4853
anomalyCode: anomalyCode,
49-
power: power
54+
power: power,
55+
nOfFibonacci: nOfFibonacci
5056
}

sketch.test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, power } = require('./sketch');
1+
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, power, nOfFibonacci } = require('./sketch');
2+
const fs = require("fs");
3+
const path = require("path");
4+
const fetch = require("node-fetch");
25

36
// test('adds 1 + 2 to equal 3', () => {
47
// expect(sum(1, 2)).toBe(3);
@@ -96,4 +99,33 @@ test('anomalyCode thousand should be 50000', () => {
9699

97100
test('power of one number', () => {
98101
expect(power(2, 2)).toBe(4);
102+
})
103+
104+
test('the 20th number of fibonacci should be 6765', () => {
105+
expect(nOfFibonacci(20)).toBe(6765);
106+
})
107+
108+
const testUrlInMarkdown = (file) => {
109+
let markdown = fs.readFileSync(file).toString();
110+
let urls = [];
111+
let regExp = /\[([^\]]+)\]\(([^)]+)\)/g;
112+
let result = null;
113+
while (result = regExp.exec(markdown)) urls.push(result[2]);
114+
return [urls.length, async () => {
115+
for (let url of urls) {
116+
if (url.includes("://") && !url.split("://")[0].includes("/")) {
117+
// An External url
118+
let res = await fetch(url);
119+
if (![200, 301, 302].includes(res.status)) throw new Error(`External Link Test: ${url} with bad response code ${res.status}`);
120+
} else {
121+
if (!fs.existsSync(path.join(path.dirname(file), url))) throw new Error(`Internal Link Test: ${url} with not found error`);
122+
}
123+
}
124+
}];
125+
}
126+
127+
it('tests url avaliability in README.md', async () => {
128+
let [testCount, testFunc] = testUrlInMarkdown("README.md");
129+
jest.setTimeout(testCount * 5000);
130+
return await testFunc();
99131
});

0 commit comments

Comments
 (0)