Skip to content

Commit

Permalink
github actions 拆分前后端测试 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Xuan authored Oct 12, 2019
1 parent 69ca3f1 commit 46dcaa0
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 18 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/browsers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: frondend 测试

on: [push]

jobs:
windows-browsers:
runs-on: windows-latest

steps:
- uses: actions/checkout@v1
- name: yarn install, test:karma, test:pptr
run: |
cd .\frondend
call yarn cache clean || exit 1
call yarn install || exit 1
call yarn run test:karma || exit 1
call yarn run test:pptr || exit 1
env:
CI: true
KARMA_SINGLE_MODE: on
# macos-browsers:
# runs-on: macos-latest

# steps:
# - uses: actions/checkout@v1
# - name: Use Node.js 10.x
# uses: actions/setup-node@v1
# with:
# node-version: 10.x
# - name: yarn install, test:karma, test:pptr
# run: |
# cd ./frondend
# yarn cache clean
# yarn install
# yarn run test:karma
# yarn run test:pptr
# env:
# CI: true
# KARMA_SINGLE_MODE: on

15 changes: 4 additions & 11 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@ on: [push]

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]

node: [8.x, 10.x, 12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ matrix.node }}
- name: install xvfb
run: sudo apt-get install xvfb
- name: yarn install, and test
run: |
cd ./backend
yarn --version
yarn cache clean
yarn install
yarn run test
cd ../frondend
yarn cache clean
yarn install
xvfb-run ./node_modules/.bin/karma start karma.config.js
npm run test:pptr
env:
CI: true
KARMA_SINGLE_MODE: on
5 changes: 3 additions & 2 deletions frondend/e2e/karma.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import App from '../App'
const E2E_TEST_ID_ATTR_NAME = 'data-e2e-test-id'

describe('App', () => {
before(() => {
before(function () {
this.timeout(15000)
const div = document.createElement('div')
div.id = 'root'
document.body.append(div)
document.body.appendChild(div)
ReactDom.render(<App />, div)
})
// after(() => {
Expand Down
17 changes: 14 additions & 3 deletions frondend/karma.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Karma configuration
// Generated on Sun Sep 29 2019 18:30:42 GMT+0800 (China Standard Time)
const os = require('os')
const { cloneDeep } = require('lodash')
const webpackDevConfig = cloneDeep(require('./webpack.dev.config'))

Expand All @@ -9,6 +10,16 @@ function isSingleRun () {
return process.env.KARMA_SINGLE_MODE === 'on'
}

const browsers = ['Chrome', 'Firefox']

if (os.platform() === 'darwin') {
browsers.push('Safari')
}

if (os.platform() === 'win32') {
browsers.push('IE')
}

module.exports = function (config) {
config.set({

Expand All @@ -19,7 +30,7 @@ module.exports = function (config) {
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],

plugins: ['karma-mocha', 'karma-chai', 'karma-webpack', 'karma-chrome-launcher', 'karma-firefox-launcher'],
plugins: ['karma-mocha', 'karma-chai', 'karma-webpack', 'karma-chrome-launcher', 'karma-firefox-launcher', 'karma-ie-launcher', 'karma-safari-launcher'],

// list of files / patterns to load in the browser
files: [
Expand Down Expand Up @@ -59,14 +70,14 @@ module.exports = function (config) {

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome', 'Firefox'],
browsers,

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: isSingleRun(),

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
concurrency: 1
})
}
2 changes: 2 additions & 0 deletions frondend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-safari-launcher": "^1.0.0",
"karma-webpack": "^4.0.2",
"less": "^3.10.3",
"less-loader": "^5.0.0",
Expand Down
14 changes: 13 additions & 1 deletion frondend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5244,13 +5244,25 @@ karma-firefox-launcher@^1.2.0:
dependencies:
is-wsl "^2.1.0"

karma-ie-launcher@^1.0.0:
version "1.0.0"
resolved "https://registry.npm.taobao.org/karma-ie-launcher/download/karma-ie-launcher-1.0.0.tgz#497986842c490190346cd89f5494ca9830c6d59c"
integrity sha1-SXmGhCxJAZA0bNifVJTKmDDG1Zw=
dependencies:
lodash "^4.6.1"

karma-mocha@^1.3.0:
version "1.3.0"
resolved "https://registry.npm.taobao.org/karma-mocha/download/karma-mocha-1.3.0.tgz#eeaac7ffc0e201eb63c467440d2b69c7cf3778bf"
integrity sha1-7qrH/8DiAetjxGdEDStpx883eL8=
dependencies:
minimist "1.2.0"

karma-safari-launcher@^1.0.0:
version "1.0.0"
resolved "https://registry.npm.taobao.org/karma-safari-launcher/download/karma-safari-launcher-1.0.0.tgz#96982a2cc47d066aae71c553babb28319115a2ce"
integrity sha1-lpgqLMR9BmquccVTursoMZEVos4=

karma-webpack@^4.0.2:
version "4.0.2"
resolved "https://registry.npm.taobao.org/karma-webpack/download/karma-webpack-4.0.2.tgz#23219bd95bdda853e3073d3874d34447c77bced0"
Expand Down Expand Up @@ -5493,7 +5505,7 @@ lodash.throttle@^4.0.0:
resolved "https://registry.npm.taobao.org/lodash.throttle/download/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=

lodash@^4.15.0, lodash@^4.16.5, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5:
lodash@^4.15.0, lodash@^4.16.5, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.6.1:
version "4.17.15"
resolved "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"husky": {
"hooks": {
"pre-commit": "standard && npm test"
"pre-commit": "standard"
}
},
"standard": {
Expand Down

0 comments on commit 46dcaa0

Please sign in to comment.