Skip to content

Commit 116a275

Browse files
committed
fix: add UTs
1 parent 7eecf44 commit 116a275

File tree

10 files changed

+12762
-5181
lines changed

10 files changed

+12762
-5181
lines changed

.github/workflows/npm-publish.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- master
1111

1212
jobs:
13+
1314
publish-npm:
1415
runs-on: ubuntu-latest
1516
steps:

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unit tests
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
node-version: [16.x, 18.x]
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- name: run unit tests
21+
run: |
22+
npm i
23+
npm test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ typings/
6363
#webstorm
6464
.idea
6565
dist
66+
coverage

__test__/index.spec.ts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import ResembleHelper from "../src";
2+
const { container } = require('codeceptjs');
3+
const helpers = container.helpers();
4+
5+
let helper = new ResembleHelper({ baseFolder: 'string',
6+
diffFolder: 'string',
7+
screenshotFolder: 'string',
8+
prepareBaseImage: 'string'})
9+
10+
describe('_getHelper()', () => {
11+
test('should return error when no matching helper found', () => {
12+
try {
13+
helper._getHelper()
14+
} catch (e: any) {
15+
expect(e.message).toEqual('No matching helper found. Supported helpers: Playwright/Puppeteer/WebDriver/TestCafe/Appium')
16+
}
17+
});
18+
19+
test('should return matching helper', () => {
20+
helpers['Playwright'] = { hello: 1 }
21+
expect(helper._getHelper()).toEqual({ hello: 1 })
22+
});
23+
})
24+
25+
26+
describe('_getPrepareBaseImage()', () => {
27+
beforeAll(() => {
28+
helpers['Playwright'] = { hello: 1 }
29+
})
30+
test('should return false when no prepareBaseImage is provided', () => {
31+
expect(helper._getPrepareBaseImage({ hello: 1 })).toBeFalsy()
32+
});
33+
34+
test('should return true when prepareBaseImage matched with config', () => {
35+
expect(helper._getPrepareBaseImage({ prepareBaseImage: 'string' })).toBeTruthy()
36+
});
37+
})
38+
39+
describe('_getDiffImagePath()', () => {
40+
beforeAll(() => {
41+
helpers['Playwright'] = { hello: 1 }
42+
})
43+
test('should return diffImagePath', () => {
44+
expect(helper._getDiffImagePath('hello')).toContain('Diff_hello.png')
45+
});
46+
47+
})
48+
49+
describe('_getActualImagePath()', () => {
50+
beforeAll(() => {
51+
helpers['Playwright'] = { hello: 1 }
52+
})
53+
test('should return ActualImagePath', () => {
54+
expect(helper._getActualImagePath('hello')).toContain('hello')
55+
});
56+
57+
})
58+
59+
describe('_getBaseImagePath()', () => {
60+
beforeAll(() => {
61+
helpers['Playwright'] = { hello: 1 }
62+
})
63+
test('should return BaseImagePath', () => {
64+
expect(helper._getBaseImagePath('hello', {})).toContain('hello')
65+
});
66+
67+
})
68+
69+
describe('resolvePath()', () => {
70+
beforeAll(() => {
71+
helpers['Playwright'] = { hello: 1 }
72+
})
73+
test('should return resolvePath', () => {
74+
expect(helper.resolvePath('hello')).toContain('hello')
75+
});
76+
77+
})

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)