Skip to content

Commit ff20724

Browse files
authored
Feature Unit Test for src\lib\ files (#11)
Feature `Unit Test` for `src\lib\` files
2 parents ed97826 + e67a128 commit ff20724

File tree

5 files changed

+144
-7
lines changed

5 files changed

+144
-7
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"env": {
3+
"test": {
4+
"plugins": ["@babel/plugin-transform-modules-commonjs"]
5+
}
6+
}
7+
}

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "lighthouse-link-thesis",
3-
"version": "0.0.4c",
3+
"version": "0.0.5c",
44
"description": "a way to automatically use lighthouse to get accessibility report number",
55
"main": "index.class.js",
66
"type": "module",
77
"scripts": {
8-
"start": "npm run clean && npm run test",
9-
"start:class": "npm run clean && npm run test:class",
10-
"test": "node index",
11-
"test:class": "node index.class",
12-
"clean": "node clean",
13-
"exp": "node test"
8+
"start": "npm run clean && npm run build",
9+
"start:class": "npm run clean && npm run build:class",
10+
"build": "node index",
11+
"build:class": "node index.class",
12+
"test": "jest",
13+
"test:debug": "jest --detectOpenHandles",
14+
"clean": "node clean"
1415
},
1516
"keywords": [
1617
"automated-tools",
@@ -21,5 +22,9 @@
2122
"dependencies": {
2223
"async": "^3.2.4",
2324
"lighthouse": "^10.2.0"
25+
},
26+
"devDependencies": {
27+
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
28+
"jest": "^29.6.2"
2429
}
2530
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Categories from "../../src/lib/categoriesHandlers.class.js"
2+
3+
const firstTestCategories = ["accessibility"]
4+
const secondTestCategories = ["accessibility", "seo", "pwa"]
5+
6+
test('getCategories from an Array', () => {
7+
expect(
8+
Categories.getFlags(firstTestCategories)
9+
).toStrictEqual("--only-categories=accessibility ");
10+
});
11+
12+
test('getCategories from an Array with more than one item', () => {
13+
expect(
14+
Categories.getFlags(secondTestCategories)
15+
).toStrictEqual("--only-categories=accessibility,seo,pwa ");
16+
});
17+
18+
test('getCurrent from Array', () => {
19+
expect(
20+
Categories.getCurrent(firstTestCategories)
21+
).toStrictEqual(["accessibility"])
22+
});
23+
24+
test('getCurrent from Array with more than one item', () => {
25+
expect(
26+
Categories.getCurrent(secondTestCategories)
27+
).toStrictEqual(["accessibility", "seo", "pwa"])
28+
});
29+
30+
test('lighthouse from Array', () => {
31+
expect(
32+
Categories.lighthouse(firstTestCategories)
33+
).toStrictEqual("accessibility")
34+
})
35+
36+
test('lighthouse from Array with more than one item', () => {
37+
expect(
38+
Categories.lighthouse(secondTestCategories)
39+
).toStrictEqual("accessibility,seo,pwa")
40+
})
41+
42+
test('getFromFlags from Array', () => {
43+
expect(
44+
Categories.getFromFlags(firstTestCategories)
45+
).toStrictEqual(["accessibility"])
46+
})
47+
48+
test('getFromFlags from empty Array', () => {
49+
expect(
50+
Categories.getFromFlags([])
51+
).toBe(undefined)
52+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Command from "../../src/lib/commandHandlers.class.js";
2+
3+
test('Create a command with options', () => {
4+
expect(
5+
Command.make('test', {
6+
"categories": ["accessibility", "seo"],
7+
"consoleLog": false
8+
})
9+
).toStrictEqual({
10+
commandToRun: 'lighthouse test --only-categories=accessibility,seo --output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"',
11+
currentFlags: '--only-categories=accessibility,seo --output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"'
12+
});
13+
});
14+
15+
test('Create a command without options', () => {
16+
expect(
17+
Command.make('test')
18+
).toStrictEqual({
19+
commandToRun: 'lighthouse test --only-categories=accessibility --output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"',
20+
currentFlags: '--only-categories=accessibility --output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"'
21+
});
22+
});

test/lib/utilites.class.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Utility from "../../src/lib/utilities.class.js"
2+
3+
test('isEmpty of an empty Array', () => {
4+
expect(
5+
Utility.isEmpty([])
6+
).toBe(true);
7+
});
8+
9+
test('isEmpty of not an empty Array', () => {
10+
expect(
11+
Utility.isEmpty(["ada"])
12+
).toBe(false);
13+
});
14+
15+
test('isEmpty of an empty Object', () => {
16+
expect(
17+
Utility.isEmpty({})
18+
).toBe(true);
19+
});
20+
21+
test('isEmpty of not an empty Object', () => {
22+
expect(
23+
Utility.isEmpty({ options: "ada" })
24+
).toBe(false);
25+
});
26+
27+
// Reverse of isEmpty
28+
test('Not isEmpty of an empty Array', () => {
29+
expect(
30+
!Utility.isEmpty([])
31+
).toBe(false);
32+
});
33+
34+
test('Not isEmpty of not an empty Array', () => {
35+
expect(
36+
!Utility.isEmpty(["ada"])
37+
).toBe(true);
38+
});
39+
40+
test('Not isEmpty of an empty Object', () => {
41+
expect(
42+
!Utility.isEmpty({})
43+
).toBe(false);
44+
});
45+
46+
test('Not isEmpty of not an empty Object', () => {
47+
expect(
48+
!Utility.isEmpty({ options: "ada" })
49+
).toBe(true);
50+
});
51+

0 commit comments

Comments
 (0)