Skip to content

Commit

Permalink
Merge pull request #551 from wheresrhys/test-built-files
Browse files Browse the repository at this point in the history
Test built files
  • Loading branch information
wheresrhys committed May 11, 2020
2 parents 4f1ef07 + bb525aa commit 1d84221
Show file tree
Hide file tree
Showing 17 changed files with 1,128 additions and 345 deletions.
203 changes: 139 additions & 64 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,47 @@ references:
filters:
tags:
only: /.*/
env: &env


nodejs: &nodejs
docker:
- image: circleci/node:12.16.3
browsers: &browsers
docker:
- image: circleci/node:12.16.3-browsers

node14: &node14
docker:
- image: circleci/node:14.2.0
node13: &node13
docker:
- image: circleci/node:13.14.0
node10: &node10
docker:
- image: circleci/node:10.20.1
env-browsers: &env-browsers
node6: &node6
docker:
- image: circleci/node:10.20.1-browsers
- image: circleci/node:6.13.0

workspace: &workspace
attach_workspace:
at: ~/project
persist: &persist
persist_to_workspace:
root: .
paths:
- .

rebuild_test: &rebuild_test
steps:
- *workspace
- run: npm rebuild
- run: FETCH_MOCK_SRC=../cjs/server.js make test


jobs:
checkout_code:
<<: *env
<<: *nodejs
steps:
- checkout
- restore_cache:
Expand All @@ -25,120 +56,164 @@ jobs:
key: npm-cache-{{ checksum "package-lock.json" }}
paths:
- node_modules
- *persist

build:
<<: *nodejs
steps:
- *workspace
- run: make build
- *persist
lint:
<<: *env
<<: *nodejs
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- *workspace
- run: make lint-ci

typecheck:
<<: *nodejs
steps:
- *workspace
- run: make typecheck

test:
<<: *nodejs
steps:
- *workspace
- run: make coverage


nodefetch2:
<<: *env
<<: *nodejs
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run: make coverage-report
- *workspace
- run: FETCH_MOCK_SRC=../cjs/server.js make test

nodefetch1:
<<: *env
<<: *nodejs
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- *workspace
- run: npm install node-fetch@1
- run: make test-unit
- run: FETCH_MOCK_SRC=../cjs/server.js make test

node6:
docker:
- image: circleci/node:6.13.0
es5:
<<: *node6
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- *workspace
- run: npm rebuild
- run: FETCH_MOCK_SRC=../es5/server.js make test-es5

esm:
<<: *node14
steps:
- *workspace
- run: npm rebuild
- run: make test-node6
- run: make test-esm

node10:
<<: *node10
<<: *rebuild_test
node13:
<<: *node13
<<: *rebuild_test

node14:
<<: *node14
<<: *rebuild_test

chrome:
<<: *env-browsers
<<: *browsers
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run: make test-chrome
- *workspace
- run: TEST_BROWSER=Chrome make test-browser

firefox:
<<: *env-browsers
<<: *browsers
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- *workspace
- run: npm install karma-firefox-launcher
- run: make test-firefox
- run: TEST_BROWSER=Firefox make test-browser

build:
<<: *env
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run: make build

deploy:
<<: *env
<<: *nodejs
steps:
- checkout
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run: 'echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ${HOME}/.npmrc'
- *workspace
- run: make publish


workflows:
version: 2
checkout_and_test:
fetch-mock-ci-cd:
jobs:
- checkout_code: *triggerable-by-tag
- nodefetch1:
- test:
<<: *triggerable-by-tag
requires:
- checkout_code
- nodefetch2:
- typecheck:
<<: *triggerable-by-tag
requires:
- checkout_code
- node6:
- lint:
<<: *triggerable-by-tag
requires:
- checkout_code
- chrome:
- build:
<<: *triggerable-by-tag
requires:
- checkout_code
# firefox version too old for sw, so postpone cross browser tests till updated in circleci
# - firefox:
# requires:
# - checkout_code
- lint:
- lint
- test
- nodefetch1:
<<: *triggerable-by-tag
requires:
- checkout_code
- build:
- build
- nodefetch2:
<<: *triggerable-by-tag
requires:
- checkout_code
- build
- es5:
<<: *triggerable-by-tag
requires:
- build
# - esm:
# <<: *triggerable-by-tag
# requires:
# - build
- node10:
<<: *triggerable-by-tag
requires:
- build
- node13:
<<: *triggerable-by-tag
requires:
- build
- node14:
<<: *triggerable-by-tag
requires:
- build
- chrome:
<<: *triggerable-by-tag
requires:
- build
- firefox:
<<: *triggerable-by-tag
requires:
- build
- deploy:
context: wheresrhys-npm-publish
requires:
- nodefetch1
- nodefetch2
- node6
- es5
- chrome
# - firefox
- lint
- firefox
- build
- typecheck
- node10
- node13
- node14
# - esm
filters:
branches:
ignore: /.*/
Expand Down
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['origami-component', 'plugin:prettier/recommended'],
"extends": ["origami-component", "plugin:prettier/recommended"],
"env": {
"browser": true,
"mocha": true,
Expand All @@ -11,8 +11,8 @@ module.exports = {
"globals": {
"expect": true
},
rules: {
'guard-for-in': 0
"rules": {
"guard-for-in": 0
}
}

43 changes: 27 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@ export PATH := $(PATH):./node_modules/.bin

.PHONY: test docs

test-dev:
karma start --browsers=Chrome
SHELL := env "PATH=$(PATH)" /bin/bash
NPM_PUBLISH_TAG := $(shell [[ "$(CIRCLE_TAG)" =~ -[a-z-]+ ]] && echo "pre-release" || echo "latest")
TEST_BROWSER := $(shell [ -z $(TEST_BROWSER) ] && echo "Chrome" || echo ${TEST_BROWSER})

test-chrome:
karma start --single-run --browsers=Chrome
# intended for local dev
test:
mocha test/server.js

test-firefox:
karma start --single-run --browsers=Firefox
test-browser:
@if [ -z $(CI) ]; \
then karma start --browsers=${TEST_BROWSER}; \
else karma start --single-run --browsers=${TEST_BROWSER}; \
fi

test-unit:
mocha test/server.js
test-es5:
node test/es5.js

test-node6: transpile
node test/node6.js
test-esm:
FETCH_MOCK_SRC=../esm/server.js ./node_modules/.bin/mocha test/server.mjs

typecheck:
dtslint --expectOnly types

lint-ci: typecheck
eslint --ignore-pattern test/fixtures/* src test
lint-ci:
eslint --ext .js,.mjs --ignore-pattern test/fixtures/* src test
prettier *.md docs/*.md docs/**/*.md

lint:
eslint --cache --fix --ignore-pattern test/fixtures/* src test
prettier --write *.md docs/*.md docs/**/*.md
eslint --cache --fix --ext .js,.mjs --ignore-pattern test/fixtures/* src test
prettier --cache --write *.md docs/*.md docs/**/*.md

coverage-report:
verify: lint

coverage:
nyc --reporter=lcovonly --reporter=text mocha test/server.js
cat ./coverage/lcov.info | coveralls

Expand All @@ -42,11 +49,15 @@ build: transpile
if [ ! -d "cjs" ]; then mkdir cjs; fi
cp -r src/* cjs
rollup -c rollup.config.js
echo '{"type": "module"}' > esm/package.json

docs:
cd docs; jekyll serve build --watch

NPM_PUBLISH_TAG := $(shell [[ "$(CIRCLE_TAG)" =~ -[a-z-]+ ]] && echo "pre-release" || echo "latest")
la:
@echo $(NPM_PUBLISH_TAG)

publish:
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > ${HOME}/.npmrc
npm version --no-git-tag-version $(CIRCLE_TAG)
npm publish --access public --tag $(NPM_PUBLISH_TAG)
4 changes: 2 additions & 2 deletions docs/_api-mocking/combined-shorthands.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |-
The atomic shorthand methods - `.once()`, `any()`, and `.get()`, `.post()`, etc. are combined into a variety of shorthand methods that blend their behaviours.
parametersBlockTitle: Methods
parameters:
- name: Any once
- name: Any once
versionAdded: 9.2.0
content: |-
Create a route that responds to any single request: `.anyOnce(response, options)`
Expand All @@ -17,7 +17,7 @@ parameters:
Create a route that only responds to a single request using a particular http method: `.getOnce()`, `.postOnce()`, `.putOnce()`, `.deleteOnce()`, `.headOnce()`, `.patchOnce()`
- name: Method any

versionAdded: 9.2.0
content: |-
Create a route that responds to any requests using a particular http method: `.getAny()`, `.postAny()`, `.putAny()`, `.deleteAny()`, `.headAny()`, `.patchAny()`
Expand Down
2 changes: 1 addition & 1 deletion docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The following request would be matched by all the mocks described below:
fetch('http://example.com/users/bob?q=rita', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{"prop1": "val1", "prop2": "val2"}'
body: '{"prop1": "val1", "prop2": "val2"}',
});
```

Expand Down
Loading

0 comments on commit 1d84221

Please sign in to comment.