Skip to content

Commit

Permalink
🤖 TEST: Run test on GitHub Action (#19)
Browse files Browse the repository at this point in the history
Only run test on Node.js >= 14
  • Loading branch information
fengmk2 authored Jun 3, 2022
1 parent 3d04360 commit a67989c
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 131 deletions.
1 change: 0 additions & 1 deletion .autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = {
'autod',
'eslint',
'eslint-config-egg',
'supertest',
],
exclude: [
'./test/fixtures',
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'

jobs:
build:
runs-on: ${{ matrix.os }}

services:
mysql:
image: mysql:5
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

strategy:
fail-fast: false
matrix:
node-version: [14, 16, 18]
os: [ubuntu-latest]

steps:
- name: Checkout Git Source
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i

- name: Continuous Integration
run: npm run ci

- name: Code Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# egg-mysql

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Node.js CI](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-mysql.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-mysql
[travis-image]: https://img.shields.io/travis/eggjs/egg-mysql.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-mysql
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-mysql.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-mysql?branch=master
[snyk-image]: https://snyk.io/test/npm/egg-mysql/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-mysql
[download-image]: https://img.shields.io/npm/dm/egg-mysql.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-mysql

Expand Down
10 changes: 1 addition & 9 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# egg-mysql

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Node.js CI](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-mysql/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-mysql.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-mysql
[travis-image]: https://img.shields.io/travis/eggjs/egg-mysql.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-mysql
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-mysql.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-mysql?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-mysql.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-mysql
[snyk-image]: https://snyk.io/test/npm/egg-mysql/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-mysql
[download-image]: https://img.shields.io/npm/dm/egg-mysql.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-mysql

Expand Down
17 changes: 0 additions & 17 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function createOneClient(config, app) {
config.user, config.host, config.port, config.database);
const client = rds(config);

app.beforeStart(function* () {
const rows = yield client.query('select now() as currentTime;');
app.beforeStart(async () => {
const rows = await client.query('select now() as currentTime;');
const index = count++;
app.coreLogger.info(`[egg-mysql] instance[${index}] status OK, rds currentTime: ${rows[0].currentTime}`);
});
Expand Down
37 changes: 24 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"eggPlugin": {
"name": "mysql"
},
"files": [
"config",
"lib",
"agent.js",
"app.js",
"index.d.ts"
],
"keywords": [
"egg",
"eggPlugin",
Expand All @@ -13,22 +20,21 @@
"database"
],
"dependencies": {
"ali-rds": "^3.0.1"
"ali-rds": "^3.4.0"
},
"devDependencies": {
"autod": "^3.0.1",
"egg": "latest-1",
"egg-bin": "^4.7.0",
"egg-ci": "^1.8.0",
"egg-mock": "^3.17.1",
"eslint": "^4.19.1",
"eslint-config-egg": "^7.0.0",
"autod": "^3.1.2",
"egg": "^2.35.0",
"egg-bin": "^4.19.0",
"egg-ci": "^2.1.0",
"egg-mock": "^4.2.1",
"eslint": "^8.16.0",
"eslint-config-egg": "^11.1.0",
"git-contributor": "^1.0.10",
"supertest": "^3.1.0",
"utility": "^1.13.1"
"utility": "^1.17.0"
},
"engines": {
"node": ">=6.0.0"
"node": ">=14.0.0"
},
"scripts": {
"contributor": "git-contributor",
Expand All @@ -40,9 +46,14 @@
"autod": "autod"
},
"ci": {
"version": "6, 8",
"version": "14, 16, 18",
"license": true,
"services": "mysql"
"service": {
"mysql": {
"version": "5",
"db": "test"
}
}
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

const execSync = require('child_process').execSync;

execSync('mysql -uroot -e "create database IF NOT EXISTS test;"');
execSync('mysql -uroot test < test/npm_auth.sql');
execSync('mysql -uroot -h 127.0.0.1 -e "create database IF NOT EXISTS test;"');
execSync('mysql -uroot -h 127.0.0.1 test < test/npm_auth.sql');
console.log('create table success');
7 changes: 3 additions & 4 deletions test/fixtures/apps/mysqlapp-dynamic/agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const co = require('co');
const fs = require('fs');
const path = require('path');

Expand All @@ -10,8 +9,8 @@ module.exports = function(agent) {
const p = path.join(__dirname, 'run/agent_result.json');
fs.existsSync(p) && fs.unlinkSync(p);

co(function* () {
const result = yield agent.mysql1.query('select now() as currentTime;');
(async () => {
const result = await agent.mysql1.query('select now() as currentTime;');
fs.writeFileSync(p, JSON.stringify(result));
}).then(done, done);
})().then(done).catch(done);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

module.exports = function* () {
const dataArr = yield this.service.user.list(this);
module.exports = async (ctx) => {
const dataArr = await ctx.service.user.list(ctx);

this.body = {
ctx.body = {
hasRows: dataArr[0].length > 0 && dataArr[1].length > 0 && dataArr[2].length > 0,
};
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

exports.list = function* (ctx) {

return yield [
exports.list = async (ctx) => {
return await Promise.all([
ctx.app.mysqls.get('db1').query('select * from npm_auth'),
ctx.app.mysqls.get('db2').query('select * from npm_auth'),
ctx.app.mysqls.get('db3').query('select * from npm_auth'),
];
]);
};
7 changes: 3 additions & 4 deletions test/fixtures/apps/mysqlapp-new/agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const co = require('co');
const fs = require('fs');
const path = require('path');

Expand All @@ -9,8 +8,8 @@ module.exports = function(agent) {
const p = path.join(__dirname, 'run/agent_result.json');
fs.existsSync(p) && fs.unlinkSync(p);

co(function* () {
const result = yield agent.mysql.query('select now() as currentTime;');
(async () => {
const result = await agent.mysql.query('select now() as currentTime;');
fs.writeFileSync(p, JSON.stringify(result));
}).then(done, done);
})().then(done).catch(done);
};
6 changes: 3 additions & 3 deletions test/fixtures/apps/mysqlapp-new/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

module.exports = function* () {
const users = yield this.service.user.list(this);
module.exports = async ctx => {
const users = await ctx.service.user.list(ctx);

this.body = {
ctx.body = {
status: 'success',
users: users,
};
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/apps/mysqlapp-new/app/service/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

exports.list = function* (ctx) {
return yield ctx.app.mysql.query('select * from npm_auth');
exports.list = async (ctx) => {
return await ctx.app.mysql.query('select * from npm_auth');
};
9 changes: 4 additions & 5 deletions test/fixtures/apps/mysqlapp/agent.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';

const co = require('co');
const fs = require('fs');
const path = require('path');

module.exports = function(agent) {
module.exports = agent => {
const done = agent.readyCallback('agent-mysql');
const p = path.join(__dirname, 'run/agent_result.json');
fs.existsSync(p) && fs.unlinkSync(p);

co(function* () {
const result = yield agent.mysql.query('select now() as currentTime;');
(async () => {
const result = await agent.mysql.query('select now() as currentTime;');
fs.writeFileSync(p, JSON.stringify(result));
}).then(done, done);
})().then(done).catch(done);
};
6 changes: 3 additions & 3 deletions test/fixtures/apps/mysqlapp/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

module.exports = function* () {
const users = yield this.service.user.list(this);
module.exports = async (ctx) => {
const users = await ctx.service.user.list(ctx);

this.body = {
ctx.body = {
status: 'success',
users,
};
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/apps/mysqlapp/app/service/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

exports.list = function* (ctx) {
return yield ctx.app.mysql.query('select * from npm_auth');
exports.list = async (ctx) => {
return await ctx.app.mysql.query('select * from npm_auth');
};
2 changes: 1 addition & 1 deletion test/fixtures/apps/mysqlapp/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports.mysql = {
password: '',
database: 'test',
},
agent:true
agent: true
};

exports.keys = 'foo';
Loading

0 comments on commit a67989c

Please sign in to comment.