Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add continuous integration #6

Open
wants to merge 2 commits into
base: version/4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PUPPETEER_PORT = 8090
PUPPETEER_OPEN_CHROME = false
16 changes: 16 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI
on: [push]
jobs:
build:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: borales/actions-yarn@v2.3.0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'
#- run: yarn install --frozen-lockfile
- run: cp .env.example .env && yarn test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/dist
.DS_Store
dist/es2015/tsconfig.tsbuildinfo
.env
3 changes: 3 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
});

window.conn = a;
window.Connector = Connector
window.Model = Model
window.RelationTypes = RelationTypes

BackdoorTech marked this conversation as resolved.
Show resolved Hide resolved
</script>
</body>
Expand Down
26 changes: 26 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// jest-puppeteer.config.js
require('dotenv').config()

const openChrome = process.env.PUPPETEER_OPEN_CHROME
const port = process.env.PUPPETEER_PORT

module.exports = {
server: {
command: `http-server -a 127.0.0.1 --port ${port} ./`,
port: port,
launchTimeout: 5000
},
launch: {
dumpio: true,
headless: openChrome != 'true',
product: 'chrome',
args: [`--window-size=1200,1080`],
defaultViewport: {
width:1200,
height:1080
},
// executablePath: chromPath
},
browserContext: 'default',

}
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"roots": [
"<rootDir>/test"
],
"testMatch": [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
// "globalSetup": "<rootDir>/test/setupJest.ts",
preset: 'jest-puppeteer',
// setupFilesAfterEnv: "<rootDir>/test/setupJest.ts",
}
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"watch": "rimraf dist && tsc -p tsconfig.build.json --watch",
"prepublish": "npm run build"
"prepublish": "npm run build",
"test": "jest --detectOpenHandles"
},
"author": "Max Gaurav max.gaurav@rubicotech.in",
"description": "A promise based ORM wrapper for indexedDB",
"devDependencies": {
"@types/jest-environment-puppeteer": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"dotenv": "^16.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"http-server": "^14.1.0",
"jest": "^27.5.1",
"jest-puppeteer": "^6.1.0",
"prettier": "^2.4.0",
"puppeteer": "^13.3.2",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3",
"ts-jest-puppeteer": "^0.0.5",
"typescript": "^4.4.3"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/migration/migration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface MigrationInterface {

export interface TableColumn {
name: string;
index: string[] | string;
index?: string[] | string;
attributes?: IDBIndexParameters;
dbIndex?: IDBIndex | null;
}
Expand Down
71 changes: 71 additions & 0 deletions test/functionl/model-no-relationship.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

import {Model as ModelType} from '../../src/index'
import {Connector as ConnectorType} from '../../src/index'
import {RelationTypes as _RelationTypes} from '../../src/index'
import { ModelKeysInterface } from '../../src/models/model.interface'
const port = process.env.PUPPETEER_PORT


describe('simple model', () => {
beforeAll(async () => {
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
})

it('Create model with one attribute that is unique', async () => {

// wait for variables to be present in the dom
await page.waitForFunction(() => 'Connector' in window);
await page.waitForFunction(() => 'Model' in window);
await page.waitForFunction(() => 'RelationTypes' in window);

await page.evaluate(() => {
const Connector: typeof ConnectorType = window['Connector']
const Model: typeof ModelType = window['Model']
const RelationTypes: typeof _RelationTypes = window['RelationTypes']

const a = new Connector({
tables: [{
name: 'admin',
columns: [{
name: 'email',
attributes: {
unique: true
}
}]
}],
name: 'sample-test',
version: 1
});

a.connect().then(async (models:ModelKeysInterface) => {
console.log(a, models);

// list the tables in th page
document.body.innerHTML = 'tables :'+JSON.stringify(Object.keys(models))
});

})

// await until the page has a visitable text 'admin'
await page.waitForFunction(() => 'admin');

expect('time not exceeded').toBe('time not exceeded')
}, 20000)
})





describe('complex model', () => {
beforeAll(async () => {
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
})

it('Check dom variables', async () => {

await page.waitForFunction(() => 'conn' in window);

expect('time not exceeded').toBe('time not exceeded')
}, 20000)
})
14 changes: 14 additions & 0 deletions test/page-load.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const port = process.env.PUPPETEER_PORT

describe('page Load', () => {
beforeAll(async () => {
await page.goto(`http://127.0.0.1:${port}/example/index.html`)
})

it('Check dom variables', async () => {

await page.waitForFunction(() => 'conn' in window);

expect('time not exceeded').toBe('time not exceeded')
}, 10000)
})
18 changes: 18 additions & 0 deletions test/unit/src/unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mergeDeep } from './../../../src/utils'

describe('utils.js', () => {


it('test function mergeDeep', async () => {

let Person = {
age: 18
}

let Car = {
Name: 'porsche'
}

expect(JSON.stringify(mergeDeep(Person, Car))).toBe(JSON.stringify({age: 18,Name:'porsche'}))
})
})
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"ES2020",
],
"module": "es6",
"moduleResolution": "classic",
"moduleResolution": "Node",
"sourceMap": true,
"target": "ES2019",
"allowJs": false,
"strict": true,
"strict": false,
"outDir": "dist",
"declarationDir": "./dist",
"incremental": true
Expand Down
Loading