diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..3edac5d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,150 @@ +version: 2.1 + +refs: + - &only_master + filters: + branches: + only: master + + - ¬_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 \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 220defb..7af9c75 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index acd662f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: node_js -node_js: - - "6" - - "8" - - "10" - - "12" - - "14" diff --git a/package.json b/package.json index d70c7d8..c8a6680 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } \ No newline at end of file diff --git a/test-import/test.js b/test-import/test.js new file mode 100644 index 0000000..50ef5e6 --- /dev/null +++ b/test-import/test.js @@ -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); +} \ No newline at end of file diff --git a/test-import/test.mjs b/test-import/test.mjs new file mode 100644 index 0000000..e90608a --- /dev/null +++ b/test-import/test.mjs @@ -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') diff --git a/test.js b/test.js index 0fa986c..bbd9b87 100644 --- a/test.js +++ b/test.js @@ -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')