diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1387026..04aff577 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,16 +8,28 @@ on: jobs: build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide build test + node-compatibility: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x, 13.x, 14.x, 15.x, 16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x] steps: - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide build - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make install install-styleguide build test + - run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make test-node-compatibility lint: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index 30bc1a2c..d4afde09 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,10 @@ scan: test: npm run test +## test - Test the project +test-node-compatibility: + npm run test:node-compatibility + ## update - Update dependencies (Unix only) update: | update-examples-submodule npm update diff --git a/package-lock.json b/package-lock.json index 8afd8d22..9991c4bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "eslint-plugin-jest": "^27.2.1", "eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-react": "^7.32.1", + "eslint-plugin-vitest-globals": "^1.5.0", "jsdoc": "^4.0.2", "prettier": "^2.8.8", "typescript": "^4.9.5 || ~5.0.0", @@ -4140,6 +4141,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/eslint-plugin-vitest-globals": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-vitest-globals/-/eslint-plugin-vitest-globals-1.5.0.tgz", + "integrity": "sha512-ZSsVOaOIig0oVLzRTyk8lUfBfqzWxr/J3/NFMfGGRIkGQPejJYmDH3gXmSJxAojts77uzAGB/UmVrwi2DC4LYA==", + "dev": true, + "license": "MIT" + }, "node_modules/eslint-rule-composer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", diff --git a/package.json b/package.json index f71ceed8..54a2a89c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "repl": "./repl.js --local ./dist/easypost.js", "scan": "npx audit-ci -m --config ./audit-ci.jsonc", "test": "cross-env NODE_ENV=test vitest run", + "test:node-compatibility": "cross-env NODE_ENV=test node ./test/node_compatibility", "watch": "vite build --watch" }, "dependencies": { @@ -62,6 +63,7 @@ "eslint-plugin-jest": "^27.2.1", "eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-react": "^7.32.1", + "eslint-plugin-vitest-globals": "^1.5.0", "jsdoc": "^4.0.2", "prettier": "^2.8.8", "typescript": "^4.9.5 || ~5.0.0", diff --git a/test/.eslintrc b/test/.eslintrc index 92165a86..170ba0da 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,26 +1,14 @@ { - "extends": ["eslint:recommended", "prettier"], + "extends": ["eslint:recommended", "prettier", "plugin:vitest-globals/recommended"], "env": { "node": true, - "mocha": true - }, - - "settings": { - "import/resolver": { - "webpack": { - "config": "webpack.config.babel.js" - } - }, - "import/extensions": ["", ".js", ".json"] + "vitest-globals/env": true }, "rules": { "import/no-extraneous-dependencies": 0, - // mocha syntax: expect(x).to.not.be.undefined - "no-unused-expressions": 0, - // @easypost/eslint-config-easypost-base assumes all tests are jest. so turn these rules off "jest/consistent-test-it": 0, "jest/valid-expect": 0, @@ -30,7 +18,6 @@ "globals": { "expect": true }, - "parser": "@babel/eslint-parser", "parserOptions": { "ecmaVersion": 13 } diff --git a/test/node_compatibility/README.md b/test/node_compatibility/README.md new file mode 100644 index 00000000..30e22552 --- /dev/null +++ b/test/node_compatibility/README.md @@ -0,0 +1,5 @@ +# Node Compatibility + +This library supports very old versions of node when importing and using the library. However, we do not support developing this library with very old versions of node. + +Thats where this folder comes in. We will run the full test suite on a modern version of Node, but will check that the library still "works" with older versions of Node using this folder. You can run this file with your API key and if it succeeds, then your version of node is compatible. Otherwise, it is not. diff --git a/test/node_compatibility/index.js b/test/node_compatibility/index.js new file mode 100644 index 00000000..60eb9c37 --- /dev/null +++ b/test/node_compatibility/index.js @@ -0,0 +1,16 @@ +const dotenv = require('dotenv'); + +dotenv.config(); + +const EasyPostClient = require('../..'); + +const test = async () => { + const apiKey = process.env.EASYPOST_TEST_API_KEY; + const client = new EasyPostClient(apiKey); + + if (!client.baseUrl.includes('easypost.com')) { + process.exit(1); + } +}; + +test(); diff --git a/test/services/easypost.test.js b/test/services/easypost.test.js index c90b9681..c79f61a5 100644 --- a/test/services/easypost.test.js +++ b/test/services/easypost.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import EasyPost, { METHODS } from '../../src/easypost'; +import EasyPostClient, { METHODS } from '../../src/easypost'; import MissingParameterError from '../../src/errors/general/missing_parameter_error'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; @@ -20,7 +20,7 @@ describe('EasyPost', function () { }); it('throws an error when no API key is provided', async function () { - expect(() => new EasyPost()).to.throw( + expect(() => new EasyPostClient()).to.throw( MissingParameterError, 'Missing required parameter: API Key.', ); diff --git a/vitest.config.js b/vitest.config.js index a3f98b10..58a3d56b 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -11,6 +11,9 @@ export default defineConfig({ coverage: { provider: 'istanbul', include: ['src/**/*.{js,ts}'], + thresholds: { + lines: 90, + }, }, }, });