Skip to content

Commit d336ec5

Browse files
author
Peter Maquiran
committed
add continuous integration
add jest add puppeteer add unit test add functional test add github actions add file .env.example don't forget to create .env file locally use the default setting in the .env.example change tsconfig.json -> strict = false change tsconfig.json -> moduleResolution = Node change TableColumn interface, the attribute index is no longer required, because it was not set while creating connection in the example/index.html
1 parent 060555c commit d336ec5

File tree

13 files changed

+4729
-32
lines changed

13 files changed

+4729
-32
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
PUPPETEER_PORT = 8090
3+
PUPPETEER_OPEN_CHROME = false

.github/workflows/build-test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
on: [push]
3+
jobs:
4+
build:
5+
name: Test
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- uses: borales/actions-yarn@v2.3.0
10+
- name: Use Node.js ${{ matrix.node-version }}
11+
uses: actions/setup-node@v2
12+
# with:
13+
# node-version: ${{ matrix.node-version }}
14+
# cache: 'npm'
15+
#- run: yarn install --frozen-lockfile
16+
- run: cp .env.example .env && yarn test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/dist
44
.DS_Store
55
dist/es2015/tsconfig.tsbuildinfo
6+
.env

example/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
});
104104

105105
window.conn = a;
106+
window['Connector'] = Connector
107+
window['Model'] = Model
108+
window['RelationTypes'] = RelationTypes
106109

107110
</script>
108111
</body>

jest-puppeteer.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// jest-puppeteer.config.js
2+
require('dotenv').config()
3+
4+
const openChrome = process.env.PUPPETEER_OPEN_CHROME
5+
const port = process.env.PUPPETEER_PORT
6+
7+
module.exports = {
8+
server: {
9+
command: `http-server -a 127.0.0.1 --port ${port} ./`,
10+
port: port,
11+
launchTimeout: 5000
12+
},
13+
launch: {
14+
dumpio: true,
15+
headless: openChrome != 'true',
16+
product: 'chrome',
17+
args: [`--window-size=1200,1080`],
18+
defaultViewport: {
19+
width:1200,
20+
height:1080
21+
},
22+
// executablePath: chromPath
23+
},
24+
browserContext: 'default',
25+
26+
}

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"roots": [
3+
"<rootDir>/test"
4+
],
5+
"testMatch": [
6+
"**/__tests__/**/*.+(ts|tsx|js)",
7+
"**/?(*.)+(spec|test).+(ts|tsx|js)"
8+
],
9+
"transform": {
10+
"^.+\\.(ts|tsx)$": "ts-jest"
11+
},
12+
// "globalSetup": "<rootDir>/test/setupJest.ts",
13+
preset: 'jest-puppeteer',
14+
// setupFilesAfterEnv: "<rootDir>/test/setupJest.ts",
15+
}

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@
88
"format": "prettier --write \"src/**/*.ts\"",
99
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1010
"watch": "rimraf dist && tsc -p tsconfig.build.json --watch",
11-
"prepublish": "npm run build"
11+
"prepublish": "npm run build",
12+
"test": "jest --detectOpenHandles"
1213
},
1314
"author": "Max Gaurav max.gaurav@rubicotech.in",
1415
"description": "A promise based ORM wrapper for indexedDB",
1516
"devDependencies": {
17+
"@types/jest-environment-puppeteer": "^5.0.0",
1618
"@typescript-eslint/eslint-plugin": "^4.31.1",
1719
"@typescript-eslint/parser": "^4.31.1",
20+
"dotenv": "^16.0.0",
1821
"eslint": "^7.32.0",
1922
"eslint-config-prettier": "^8.3.0",
2023
"eslint-plugin-prettier": "^4.0.0",
24+
"http-server": "^14.1.0",
25+
"jest": "^27.5.1",
26+
"jest-puppeteer": "^6.1.0",
2127
"prettier": "^2.4.0",
28+
"puppeteer": "^13.3.2",
2229
"rimraf": "^3.0.2",
30+
"ts-jest": "^27.1.3",
31+
"ts-jest-puppeteer": "^0.0.5",
2332
"typescript": "^4.4.3"
2433
},
2534
"files": [

src/migration/migration.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface MigrationInterface {
2020

2121
export interface TableColumn {
2222
name: string;
23-
index: string[] | string;
23+
index?: string[] | string;
2424
attributes?: IDBIndexParameters;
2525
dbIndex?: IDBIndex | null;
2626
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
import {Model as ModelType} from '../../src/index'
3+
import {Connector as ConnectorType} from '../../src/index'
4+
import {RelationTypes as _RelationTypes} from '../../src/index'
5+
import { ModelKeysInterface } from '../../src/models/model.interface'
6+
const port = process.env.PUPPETEER_PORT
7+
8+
9+
describe('simple model', () => {
10+
beforeAll(async () => {
11+
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
12+
})
13+
14+
it('Create model with one attribute that is required', async () => {
15+
16+
// wait for variables to be present in the dom
17+
await page.waitForFunction(() => 'Connector' in window);
18+
await page.waitForFunction(() => 'Model' in window);
19+
await page.waitForFunction(() => 'RelationTypes' in window);
20+
21+
await page.evaluate(() => {
22+
const Connector: typeof ConnectorType = window['Connector']
23+
const Model: typeof ModelType = window['Model']
24+
const RelationTypes: typeof _RelationTypes = window['RelationTypes']
25+
26+
const a = new Connector({
27+
tables: [{
28+
name: 'admin',
29+
columns: [{
30+
name: 'email',
31+
attributes: {
32+
unique: true
33+
}
34+
}]
35+
}],
36+
name: 'sample-test',
37+
version: 1
38+
});
39+
40+
a.connect().then(async (models:ModelKeysInterface) => {
41+
console.log(a, models);
42+
43+
// list the tables in th page
44+
document.body.innerHTML = 'tables :'+JSON.stringify(Object.keys(models))
45+
});
46+
47+
})
48+
49+
// await until the page has a visitable text 'admin'
50+
await page.waitForFunction(() => 'admin');
51+
52+
expect('time not exceeded').toBe('time not exceeded')
53+
}, 20000)
54+
})
55+
56+
57+
58+
59+
60+
describe('complex model', () => {
61+
beforeAll(async () => {
62+
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
63+
})
64+
65+
it('Check dom variables', async () => {
66+
67+
await page.waitForFunction(() => 'conn' in window);
68+
69+
expect('time not exceeded').toBe('time not exceeded')
70+
}, 20000)
71+
})

test/page-load.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const port = process.env.PUPPETEER_PORT
2+
3+
describe('page Load', () => {
4+
beforeAll(async () => {
5+
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
6+
})
7+
8+
it('Check dom variables', async () => {
9+
10+
await page.waitForFunction(() => 'conn' in window);
11+
12+
expect('time not exceeded').toBe('time not exceeded')
13+
}, 10000)
14+
})

test/unit/src/unit.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { mergeDeep } from './../../../src/utils'
2+
3+
describe('utils.js', () => {
4+
5+
6+
it('test function mergeDeep', async () => {
7+
8+
let Person = {
9+
age: 18
10+
}
11+
12+
let Car = {
13+
Name: 'porsche'
14+
}
15+
16+
expect(JSON.stringify(mergeDeep(Person, Car))).toBe(JSON.stringify({age: 18,Name:'porsche'}))
17+
})
18+
})

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"ES2020",
1111
],
1212
"module": "es6",
13-
"moduleResolution": "classic",
13+
"moduleResolution": "Node",
1414
"sourceMap": true,
1515
"target": "ES2019",
1616
"allowJs": false,
17-
"strict": true,
17+
"strict": false,
1818
"outDir": "dist",
1919
"declarationDir": "./dist",
2020
"incremental": true

0 commit comments

Comments
 (0)