From 33fea3b3dab52ee4fdeb3078a1505edfc339f16e Mon Sep 17 00:00:00 2001 From: Alex Matthews Date: Sun, 22 Dec 2024 16:12:37 -0600 Subject: [PATCH] Makes changes to github workflows --- .github/workflows/ci.yml | 14 +++++++++++++- Makefile | 4 ++++ package-lock.json | 8 ++++++++ package.json | 2 ++ test/.eslintrc | 17 ++--------------- test/node_compatibility/README.md | 5 +++++ test/node_compatibility/index.js | 16 ++++++++++++++++ test/services/easypost.test.js | 4 ++-- vitest.config.js | 3 +++ 9 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 test/node_compatibility/README.md create mode 100644 test/node_compatibility/index.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e13870264..04aff5776 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 30bc1a2c5..d4afde093 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 8afd8d226..9991c4bb7 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 f71ceed8a..54a2a89c7 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 92165a86e..170ba0da5 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 000000000..30e225528 --- /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 000000000..60eb9c37d --- /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 c90b96814..c79f61a51 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 a3f98b107..58a3d56b2 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, + }, }, }, });