Skip to content

Commit

Permalink
ci: setup circleci (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Apr 26, 2020
1 parent 34dc9f8 commit 8e7187d
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 75 deletions.
150 changes: 150 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
version: 2.1

refs:
- &only_master
filters:
branches:
only: master

- &not_master
filters:
branches:
ignore: master

workflows:
test:
jobs:
- unit-tests:
<<: *not_master
name: node-6
version: '6'
- unit-tests:
<<: *not_master
name: node-8
version: '8'
- unit-tests:
<<: *not_master
name: node-10
version: '10'
- unit-tests:
<<: *not_master
name: node-12
version: '12'
- unit-tests:
<<: *not_master
name: node-14
version: '14'

release:
jobs:
- unit-tests:
<<: *only_master
name: node-6
version: '6'
- unit-tests:
<<: *only_master
name: node-8
version: '8'
- unit-tests:
<<: *only_master
name: node-10
version: '10'
- unit-tests:
<<: *only_master
name: node-12
version: '12'
- unit-tests:
<<: *only_master
name: node-14
version: '14'

- publish-dry-run:
<<: *only_master
context: common-env

- publish-approval:
type: approval
context: common-env
requires:
- publish-dry-run

- publish:
<<: *only_master
context: common-env
requires:
- node-6
- node-8
- node-10
- node-12
- node-14
- publish-approval

jobs:
unit-tests:
parameters:
version:
type: string
docker:
- image: circleci/node:<< parameters.version >>
steps:
- setup
- test

publish-dry-run:
docker:
- image: circleci/node:12
steps:
- setup
- publish-dry-run

publish:
docker:
- image: circleci/node:12
steps:
- setup
- publish

commands:
setup:
description: 'Checkout and install dependencies'
steps:
- checkout
- run:
name: Versions
command: node -v && npm -v
- run:
name: Install Dependencies
command: npm i

test:
steps:
- run:
name: Test
command: npm test
- run:
name: Pack
command: npm pack
- run:
name: Setup Import Test
command: echo $PWD && cd .. && mkdir test-import && cp -a project/test-import/ test-import/test-import/ && cd test-import && npm init -y && npm i ../project/is-promise-2.2.2.tgz
- run:
name: Test Import
command: cd ../test-import && node test-import/test.js

publish-dry-run:
steps:
- run:
name: NPM Auth
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Release (Dry Run)
command: npx rollingversions publish --dry-run

publish:
steps:
- run:
name: NPM Auth
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Release
command: npx rollingversions publish
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [ForbesLindesay]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: [ForbesLindesay] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Test whether an object looks like a promises-a+ promise",
"main": "./index.js",
"scripts": {
"test": "mocha -R spec"
"test": "node test"
},
"files": [
"index.js",
Expand All @@ -15,9 +15,5 @@
"url": "https://github.com/then/is-promise.git"
},
"author": "ForbesLindesay",
"license": "MIT",
"devDependencies": {
"better-assert": "^1.0.2",
"mocha": "~1.7.4"
}
"license": "MIT"
}
35 changes: 35 additions & 0 deletions test-import/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var assert = require('assert');
var isPromise = require('is-promise');


assert(isPromise(null) === false);
assert(isPromise(undefined) === false);
assert(isPromise(0) === false);
assert(isPromise(-42) === false);
assert(isPromise(42) === false);
assert(isPromise('') === false);
assert(isPromise('then') === false);
assert(isPromise(false) === false);
assert(isPromise(true) === false);
assert(isPromise({}) === false);
assert(isPromise({then: true}) === false);
assert(isPromise([]) === false);
assert(isPromise([true]) === false);
assert(isPromise(() => {}) === false);

// This looks similar enough to a promise
// that promises/A+ says we should treat
// it as a promise.
var promise = {then: function () {}};

assert(isPromise(promise) === true);
const fn = () => {};
fn.then = () => {};
assert(isPromise(fn) === true);

console.log('CommonJS tests passed')

if(parseInt(process.version.split('.')[0].substr(1), 10) >= 14) {
const result = require('child_process').spawnSync('node', ['test.mjs'], {cwd: __dirname, stdio: 'inherit'});
process.exit(result.status);
}
30 changes: 30 additions & 0 deletions test-import/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from 'assert';
import isPromise from 'is-promise';


assert(isPromise(null) === false);
assert(isPromise(undefined) === false);
assert(isPromise(0) === false);
assert(isPromise(-42) === false);
assert(isPromise(42) === false);
assert(isPromise('') === false);
assert(isPromise('then') === false);
assert(isPromise(false) === false);
assert(isPromise(true) === false);
assert(isPromise({}) === false);
assert(isPromise({then: true}) === false);
assert(isPromise([]) === false);
assert(isPromise([true]) === false);
assert(isPromise(() => {}) === false);

// This looks similar enough to a promise
// that promises/A+ says we should treat
// it as a promise.
var promise = {then: function () {}};

assert(isPromise(promise) === true);
const fn = () => {};
fn.then = () => {};
assert(isPromise(fn) === true);

console.log('ES Modules tests passed')
84 changes: 23 additions & 61 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,30 @@
var assert = require('assert');
var isPromise = require('./');
var assert = require('better-assert');


assert(isPromise(null) === false);
assert(isPromise(undefined) === false);
assert(isPromise(0) === false);
assert(isPromise(-42) === false);
assert(isPromise(42) === false);
assert(isPromise('') === false);
assert(isPromise('then') === false);
assert(isPromise(false) === false);
assert(isPromise(true) === false);
assert(isPromise({}) === false);
assert(isPromise({then: true}) === false);
assert(isPromise([]) === false);
assert(isPromise([true]) === false);
assert(isPromise(() => {}) === false);

// This looks similar enough to a promise
// that promises/A+ says we should treat
// it as a promise.
var promise = {then: function () {}};

describe('calling isPromise', function () {
describe('with a promise', function () {
it('returns true', function () {
assert(isPromise(promise));
});
});
describe('with null', function () {
it('returns false', function () {
assert(isPromise(null) === false);
});
});
describe('with undefined', function () {
it('returns false', function () {
assert(isPromise(undefined) === false);
});
});
describe('with a number', function () {
it('returns false', function () {
assert(!isPromise(0));
assert(!isPromise(-42));
assert(!isPromise(42));
});
});
describe('with a string', function () {
it('returns false', function () {
assert(!isPromise(''));
assert(!isPromise('then'));
});
});
describe('with a bool', function () {
it('returns false', function () {
assert(!isPromise(false));
assert(!isPromise(true));
});
});
describe('with an object', function () {
it('returns false', function () {
assert(!isPromise({}));
assert(!isPromise({then: true}));
});
});
describe('with an array', function () {
it('returns false', function () {
assert(!isPromise([]));
assert(!isPromise([true]));
});
});
describe('with a func', function () {
it('returns false', function () {
assert(!isPromise(() => {}));
});
});
describe('with a func with .then method', function () {
it('returns true', function () {
const fn = () => {};
fn.then = () => {};
assert(isPromise(fn));
});
});
});
assert(isPromise(promise) === true);
const fn = () => {};
fn.then = () => {};
assert(isPromise(fn) === true);

console.log('tests passed')

0 comments on commit 8e7187d

Please sign in to comment.