Test CommonJS build artifact (#838)

* common js artefact build

* add GitHub Action
This commit is contained in:
Konstantin Vyatkin 2020-05-26 09:50:51 -04:00 committed by GitHub
parent d1691f990a
commit 966a4c3c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 1 deletions

30
.github/workflows/commonjs.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: CI
on:
push:
branches: [master]
pull_request:
paths:
- src/**.js
- package.json
- test/commonjs/**
- rollup.config.js
- .github/workflows/commonjs.yml
jobs:
commonjs-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Node.JS version from package.json
id: get-versions
run: echo ::set-output name=node::$(jq -r .engines.node ./package.json | sed 's/[^0-9.]//g')
- uses: actions/setup-node@v1
with:
node-version: ${{steps.get-versions.outputs.node}}
- run: npm install
- run: npm run prepublishOnly

View File

@ -24,7 +24,8 @@
"test": "node --experimental-modules node_modules/c8/bin/c8 --reporter=html --reporter=lcov --reporter=text --check-coverage node --experimental-modules node_modules/mocha/bin/mocha",
"coverage": "c8 report --reporter=text-lcov | coveralls",
"test-types": "tsd",
"lint": "xo"
"lint": "xo",
"prepublishOnly": "node ./test/commonjs/test-artifact.js"
},
"repository": {
"type": "git",

View File

@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

@ -0,0 +1,41 @@
// @ts-nocheck
/**
* Rebuild first
*/
const {execFileSync} = require('child_process');
console.log('Building CommonJS version...');
execFileSync('npm', ['run', 'build'], {stdio: 'inherit'});
const assert = require('assert');
const fetch = require('../../');
assert.strictEqual(
typeof fetch,
'function',
'default import must be a function'
);
const {Request, Response, Headers, FetchError, AbortError} = require('../../');
assert.ok(new FetchError() instanceof Error, 'FetchError must be an Error');
assert.ok(
new AbortError() instanceof Error,
'AbortError must be an extension of Error'
);
assert.ok(
new Request('https://www.test.com').headers instanceof Headers,
'Request class is not exposing correct functionality'
);
assert.strictEqual(
new Response(null, {headers: {a: 'a'}}).headers.get('a'),
'a',
'Response class is not exposing correct functionality'
);
fetch(
`data:text/plain;base64,${Buffer.from('Hello World!').toString('base64')}`
)
.then(res => res.text())
.then(text => assert.strictEqual(text, 'Hello World!'))
.then(() => {
console.info('✅ CommonJS build artefact fitness testes successfully');
});