diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f5e161f89..1639a4f5e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,40 @@ on: [push, pull_request] permissions: contents: read # to fetch code (actions/checkout) jobs: + Setup: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v2 + with: + node-version: 16 + cache: npm + - run: npm install --ignore-scripts + - run: npm run build + env: + PUBLISH: true + - uses: actions/cache@v3 + with: + # cache key based on OS as the full path for each OS may be different + # and windows is not able to reuse the cache from ubuntu + key: output-${{ github.run_id }}-${{ matrix.os }} + path: | + index.* + compiler.* + ssr.* + action/ + animate/ + easing/ + internal/ + motion/ + store/ + transition/ + types/ Tests: + needs: Setup runs-on: ${{ matrix.os }} timeout-minutes: 15 strategy: @@ -16,7 +49,22 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: npm - - run: npm install + - uses: actions/cache@v3 + with: + key: output-${{ github.run_id }}-${{ matrix.os }} + path: | + index.* + compiler.* + ssr.* + action/ + animate/ + easing/ + internal/ + motion/ + store/ + transition/ + types/ + - run: npm install --ignore-scripts - run: npm test env: CI: true @@ -40,4 +88,5 @@ jobs: - uses: actions/setup-node@v2 with: cache: npm - - run: 'npm i && npm run test:unit' + - run: npm install --ignore-scripts + - run: npm run test:unit diff --git a/.mocharc.js b/.mocharc.js index e55f26099e..449f81ecd6 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,7 +1,7 @@ +const is_unit_test = process.env.UNIT_TEST; + module.exports = { - file: [ - 'test/test.ts' - ], + file: is_unit_test ? [] : ['test/test.ts'], require: [ 'sucrase/register' ] diff --git a/.mocharc.unit.js b/.mocharc.unit.js new file mode 100644 index 0000000000..387d70e7e0 --- /dev/null +++ b/.mocharc.unit.js @@ -0,0 +1,15 @@ +module.exports = { + spec: [ + 'src/**/__test__.ts', + ], + require: [ + 'sucrase/register' + ], + recursive: true, +}; + +// add coverage options when running 'npx c8 mocha' +if (process.env.NODE_V8_COVERAGE) { + module.exports.fullTrace = true; + module.exports.require.push('source-map-support/register'); +} diff --git a/package.json b/package.json index bf6b9e7754..1fcbc8e48e 100644 --- a/package.json +++ b/package.json @@ -87,14 +87,13 @@ "types": "types/runtime/index.d.ts", "scripts": { "test": "mocha --exit", - "test:unit": "mocha --require sucrase/register --recursive src/**/__test__.ts --exit", - "quicktest": "mocha", + "test:unit": "mocha --config .mocharc.unit.js --exit", + "quicktest": "mocha --exit", "build": "rollup -c && npm run tsd", "prepare": "npm run build", "dev": "rollup -cw", - "pretest": "npm run build", "posttest": "agadoo internal/index.mjs", - "prepublishOnly": "node check_publish_env.js && npm run lint && npm test", + "prepublishOnly": "node check_publish_env.js && npm run lint && npm run build && npm test", "tsd": "node ./generate-type-definitions.js", "lint": "eslint \"{src,test}/**/*.{ts,js}\"" },