mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
refactor: remove old test suite update docs (#7498)
* chore: update all ci workflows * chore: added readme for tests * chore: fix release branch * Update .github/workflows/release-branch.yml Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -12,7 +12,6 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
|
|||||||
@@ -21,12 +21,112 @@ permissions:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
build-and-run-vitest:
|
||||||
|
name: Build and run vitest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: true
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: 24.x
|
||||||
|
cache: npm
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Build project
|
||||||
|
run: npm run build
|
||||||
|
- name: Install Playwright with deps
|
||||||
|
run: npx playwright install --with-deps
|
||||||
|
- name: Run unit tests
|
||||||
|
run: npm run test:vitest:unit
|
||||||
|
- name: Run browser tests
|
||||||
|
run: npm run test:vitest:browser:headless
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: axios
|
||||||
|
path: dist
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
cjs-smoke-tests:
|
||||||
|
name: CJS smoke tests (Node ${{ matrix.node-version }})
|
||||||
|
needs: build-and-run-vitest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
node-version: [12, 14, 16, 18]
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: true
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: tests/smoke/cjs/package-lock.json
|
||||||
|
- name: Install dependencies
|
||||||
|
if: matrix.node-version == 16 || matrix.node-version == 18
|
||||||
|
run: npm ci
|
||||||
|
- name: Download build artifact
|
||||||
|
uses: actions/download-artifact@v8
|
||||||
|
with:
|
||||||
|
name: axios
|
||||||
|
path: dist
|
||||||
|
- name: Install CJS smoke test dependencies
|
||||||
|
working-directory: tests/smoke/cjs
|
||||||
|
run: npm install
|
||||||
|
- name: Run CJS smoke tests
|
||||||
|
working-directory: tests/smoke/cjs
|
||||||
|
run: npm run test:smoke:cjs:mocha
|
||||||
|
|
||||||
|
esm-smoke-tests:
|
||||||
|
name: ESM smoke tests (Node ${{ matrix.node-version }})
|
||||||
|
needs: build-and-run-vitest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
node-version: [20, 22, 24]
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: true
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: tests/smoke/esm/package-lock.json
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Download build artifact
|
||||||
|
uses: actions/download-artifact@v8
|
||||||
|
with:
|
||||||
|
name: axios
|
||||||
|
path: dist
|
||||||
|
- name: Install ESM smoke test dependencies
|
||||||
|
working-directory: tests/smoke/esm
|
||||||
|
run: npm install
|
||||||
|
- name: Run ESM smoke tests
|
||||||
|
working-directory: tests/smoke/esm
|
||||||
|
run: npm run test:smoke:esm:vitest
|
||||||
|
|
||||||
|
bump-version-and-create-pr:
|
||||||
|
name: Bump version and create PR
|
||||||
|
needs: [build-and-run-vitest, cjs-smoke-tests, esm-smoke-tests]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
@@ -61,19 +161,13 @@ jobs:
|
|||||||
run: npm run preversion
|
run: npm run preversion
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: Run unit tests
|
|
||||||
run: npm run test:node
|
|
||||||
- name: Run package tests
|
|
||||||
run: npm run test:package
|
|
||||||
- name: Run browser tests
|
|
||||||
run: npm run test:browser
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v8
|
uses: peter-evans/create-pull-request@v8
|
||||||
with:
|
with:
|
||||||
branch: "release"
|
branch: 'release'
|
||||||
commit-message: "chore(release): prepare release ${{ steps.bump-version.outputs.newTag }}"
|
commit-message: 'chore(release): prepare release ${{ steps.bump-version.outputs.newTag }}'
|
||||||
body: "This PR prepares the release ${{ steps.bump-version.outputs.newTag }}."
|
body: 'This PR prepares the release ${{ steps.bump-version.outputs.newTag }}.'
|
||||||
title: "chore(release): prepare release ${{ steps.bump-version.outputs.newTag }}"
|
title: 'chore(release): prepare release ${{ steps.bump-version.outputs.newTag }}'
|
||||||
maintainer-can-modify: true
|
maintainer-can-modify: true
|
||||||
draft: false
|
draft: false
|
||||||
labels: |
|
labels: |
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
build-and-run-vitest:
|
||||||
|
name: Build and run vitest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
@@ -46,7 +47,7 @@ jobs:
|
|||||||
|
|
||||||
cjs-smoke-tests:
|
cjs-smoke-tests:
|
||||||
name: CJS smoke tests (Node ${{ matrix.node-version }})
|
name: CJS smoke tests (Node ${{ matrix.node-version }})
|
||||||
needs: ci
|
needs: build-and-run-vitest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
@@ -80,7 +81,7 @@ jobs:
|
|||||||
|
|
||||||
esm-smoke-tests:
|
esm-smoke-tests:
|
||||||
name: ESM smoke tests (Node ${{ matrix.node-version }})
|
name: ESM smoke tests (Node ${{ matrix.node-version }})
|
||||||
needs: ci
|
needs: build-and-run-vitest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|||||||
-224
@@ -1,224 +0,0 @@
|
|||||||
/* eslint-disable no-console */
|
|
||||||
/* eslint-disable no-unused-vars */
|
|
||||||
/* eslint-disable func-names */
|
|
||||||
// Karma configuration
|
|
||||||
// Generated on Fri Aug 15 2014 23:11:13 GMT-0500 (CDT)
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var resolve = require('@rollup/plugin-node-resolve').default;
|
|
||||||
var commonjs = require('@rollup/plugin-commonjs');
|
|
||||||
|
|
||||||
function createCustomLauncher(browser, version, platform) {
|
|
||||||
return {
|
|
||||||
base: 'SauceLabs',
|
|
||||||
browserName: browser,
|
|
||||||
version: version,
|
|
||||||
platform: platform,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function (config) {
|
|
||||||
var customLaunchers = {};
|
|
||||||
var browsers = process.env.Browsers && process.env.Browsers.split(',');
|
|
||||||
var sauceLabs;
|
|
||||||
|
|
||||||
if (process.env.SAUCE_USERNAME || process.env.SAUCE_ACCESS_KEY) {
|
|
||||||
customLaunchers = {};
|
|
||||||
|
|
||||||
var runAll = true;
|
|
||||||
var options = [
|
|
||||||
'SAUCE_CHROME',
|
|
||||||
'SAUCE_FIREFOX',
|
|
||||||
'SAUCE_SAFARI',
|
|
||||||
'SAUCE_OPERA',
|
|
||||||
'SAUCE_IE',
|
|
||||||
'SAUCE_EDGE',
|
|
||||||
'SAUCE_IOS',
|
|
||||||
'SAUCE_ANDROID',
|
|
||||||
];
|
|
||||||
|
|
||||||
options.forEach(function (opt) {
|
|
||||||
if (process.env[opt]) {
|
|
||||||
runAll = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Chrome
|
|
||||||
if (runAll || process.env.SAUCE_CHROME) {
|
|
||||||
customLaunchers.SL_Chrome = createCustomLauncher('chrome');
|
|
||||||
// customLaunchers.SL_ChromeDev = createCustomLauncher('chrome', 'dev');
|
|
||||||
// customLaunchers.SL_ChromeBeta = createCustomLauncher('chrome', 'beta');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Firefox
|
|
||||||
if (runAll || process.env.SAUCE_FIREFOX) {
|
|
||||||
//customLaunchers.SL_Firefox = createCustomLauncher('firefox');
|
|
||||||
// customLaunchers.SL_FirefoxDev = createCustomLauncher('firefox', 'dev');
|
|
||||||
// customLaunchers.SL_FirefoxBeta = createCustomLauncher('firefox', 'beta');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safari
|
|
||||||
if (runAll || process.env.SAUCE_SAFARI) {
|
|
||||||
// customLaunchers.SL_Safari7 = createCustomLauncher('safari', 7);
|
|
||||||
// customLaunchers.SL_Safari8 = createCustomLauncher('safari', 8);
|
|
||||||
customLaunchers.SL_Safari9 = createCustomLauncher('safari', 9.0, 'OS X 10.11');
|
|
||||||
customLaunchers.SL_Safari10 = createCustomLauncher('safari', '10.1', 'macOS 10.12');
|
|
||||||
customLaunchers.SL_Safari11 = createCustomLauncher('safari', '11.1', 'macOS 10.13');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Opera
|
|
||||||
if (runAll || process.env.SAUCE_OPERA) {
|
|
||||||
// TODO The available versions of Opera are too old and lack basic APIs
|
|
||||||
// customLaunchers.SL_Opera11 = createCustomLauncher('opera', 11, 'Windows XP');
|
|
||||||
// customLaunchers.SL_Opera12 = createCustomLauncher('opera', 12, 'Windows 7');
|
|
||||||
}
|
|
||||||
|
|
||||||
// IE
|
|
||||||
if (runAll || process.env.SAUCE_IE) {
|
|
||||||
customLaunchers.SL_IE11 = createCustomLauncher('internet explorer', 11, 'Windows 8.1');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edge
|
|
||||||
if (runAll || process.env.SAUCE_EDGE) {
|
|
||||||
customLaunchers.SL_Edge = createCustomLauncher('microsoftedge', null, 'Windows 10');
|
|
||||||
}
|
|
||||||
|
|
||||||
// IOS
|
|
||||||
if (runAll || process.env.SAUCE_IOS) {
|
|
||||||
// TODO IOS7 capture always timesout
|
|
||||||
// customLaunchers.SL_IOS7 = createCustomLauncher('iphone', '7.1', 'OS X 10.10');
|
|
||||||
// TODO Mobile browsers are causing failures, possibly from too many concurrent VMs
|
|
||||||
// customLaunchers.SL_IOS8 = createCustomLauncher('iphone', '8.4', 'OS X 10.10');
|
|
||||||
// customLaunchers.SL_IOS9 = createCustomLauncher('iphone', '9.2', 'OS X 10.10');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Android
|
|
||||||
if (runAll || process.env.SAUCE_ANDROID) {
|
|
||||||
// TODO Mobile browsers are causing failures, possibly from too many concurrent VMs
|
|
||||||
// customLaunchers.SL_Android4 = createCustomLauncher('android', '4.4', 'Linux');
|
|
||||||
// customLaunchers.SL_Android5 = createCustomLauncher('android', '5.1', 'Linux');
|
|
||||||
}
|
|
||||||
|
|
||||||
browsers = Object.keys(customLaunchers);
|
|
||||||
|
|
||||||
sauceLabs = {
|
|
||||||
recordScreenshots: false,
|
|
||||||
connectOptions: {
|
|
||||||
// port: 5757,
|
|
||||||
logfile: 'sauce_connect.log',
|
|
||||||
},
|
|
||||||
public: 'public',
|
|
||||||
};
|
|
||||||
} else if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') {
|
|
||||||
console.log(
|
|
||||||
'Cannot run on Sauce Labs as encrypted environment variables are not available to PRs. ' +
|
|
||||||
'Running on Travis.'
|
|
||||||
);
|
|
||||||
browsers = ['Firefox'];
|
|
||||||
} else if (process.env.GITHUB_ACTIONS === 'true') {
|
|
||||||
console.log('Running ci on GitHub Actions.');
|
|
||||||
browsers = ['FirefoxHeadless', 'ChromeHeadless'];
|
|
||||||
} else {
|
|
||||||
browsers = browsers || ['Chrome'];
|
|
||||||
console.log(
|
|
||||||
`Running ${browsers} locally since SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are not set.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
config.set({
|
|
||||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|
||||||
basePath: '',
|
|
||||||
|
|
||||||
// frameworks to use
|
|
||||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|
||||||
frameworks: ['jasmine-ajax', 'jasmine', 'sinon'],
|
|
||||||
|
|
||||||
// list of files / patterns to load in the browser
|
|
||||||
files: [
|
|
||||||
{ pattern: 'test/specs/__helpers.js', watched: false },
|
|
||||||
{ pattern: 'test/specs/**/*.spec.js', watched: false },
|
|
||||||
],
|
|
||||||
|
|
||||||
// list of files to exclude
|
|
||||||
exclude: [],
|
|
||||||
|
|
||||||
// preprocess matching files before serving them to the browser
|
|
||||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|
||||||
preprocessors: {
|
|
||||||
'test/specs/__helpers.js': ['rollup'],
|
|
||||||
'test/specs/**/*.spec.js': ['rollup'],
|
|
||||||
},
|
|
||||||
|
|
||||||
rollupPreprocessor: {
|
|
||||||
plugins: [resolve({ browser: true }), commonjs()],
|
|
||||||
output: {
|
|
||||||
format: 'iife',
|
|
||||||
name: '_axios',
|
|
||||||
sourcemap: 'inline',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// test results reporter to use
|
|
||||||
// possible values: 'dots', 'progress'
|
|
||||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|
||||||
// Disable code coverage, as it's breaking CI:
|
|
||||||
// reporters: ['dots', 'coverage', 'saucelabs'],
|
|
||||||
reporters: ['progress'],
|
|
||||||
|
|
||||||
// web server port
|
|
||||||
port: 9876,
|
|
||||||
|
|
||||||
// Increase timeouts to prevent the issue with disconnected tests (https://goo.gl/nstA69)
|
|
||||||
captureTimeout: 4 * 60 * 1000,
|
|
||||||
browserDisconnectTimeout: 10000,
|
|
||||||
browserDisconnectTolerance: 1,
|
|
||||||
browserNoActivityTimeout: 4 * 60 * 1000,
|
|
||||||
|
|
||||||
// enable / disable colors in the output (reporters and logs)
|
|
||||||
colors: true,
|
|
||||||
|
|
||||||
// level of logging
|
|
||||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|
||||||
logLevel: config.LOG_INFO,
|
|
||||||
|
|
||||||
// enable / disable watching file and executing tests whenever any file changes
|
|
||||||
autoWatch: false,
|
|
||||||
|
|
||||||
// start these browsers
|
|
||||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|
||||||
browsers: browsers,
|
|
||||||
|
|
||||||
// Continuous Integration mode
|
|
||||||
// if true, Karma captures browsers, runs the tests and exits
|
|
||||||
singleRun: false,
|
|
||||||
|
|
||||||
// Webpack config
|
|
||||||
webpack: {
|
|
||||||
mode: 'development',
|
|
||||||
cache: true,
|
|
||||||
devtool: 'inline-source-map',
|
|
||||||
externals: [
|
|
||||||
{
|
|
||||||
'./adapters/http': 'var undefined',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
webpackServer: {
|
|
||||||
stats: {
|
|
||||||
colors: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Coverage reporting
|
|
||||||
coverageReporter: {
|
|
||||||
type: 'lcov',
|
|
||||||
dir: 'coverage/',
|
|
||||||
subdir: '.',
|
|
||||||
},
|
|
||||||
|
|
||||||
sauceLabs: sauceLabs,
|
|
||||||
customLaunchers: customLaunchers,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
+4
-16
@@ -45,28 +45,16 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run test:node && npm run test:browser && npm run test:package",
|
"build": "gulp clear && cross-env NODE_ENV=production rollup -c -m",
|
||||||
"test:node": "npm run test:mocha",
|
"version": "npm run build && git add package.json",
|
||||||
"test:node:coverage": "c8 npm run test:mocha",
|
"preversion": "gulp version",
|
||||||
"test:browser": "npm run test:karma",
|
"test": "npm run test:vitest",
|
||||||
"test:vitest": "vitest run",
|
"test:vitest": "vitest run",
|
||||||
"test:vitest:unit": "vitest run --project unit",
|
"test:vitest:unit": "vitest run --project unit",
|
||||||
"test:vitest:browser": "vitest run --project browser",
|
"test:vitest:browser": "vitest run --project browser",
|
||||||
"test:vitest:browser:headless": "vitest run --project browser-headless",
|
"test:vitest:browser:headless": "vitest run --project browser-headless",
|
||||||
"test:vitest:watch": "vitest",
|
"test:vitest:watch": "vitest",
|
||||||
"test:package": "npm run test:eslint && npm run test:exports",
|
|
||||||
"test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
|
|
||||||
"test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
|
|
||||||
"test:exports": "node bin/ssl_hotfix.js mocha test/module/test.js --timeout 30000 --exit",
|
|
||||||
"test:karma": "node ./bin/run-karma-tests.js",
|
|
||||||
"test:karma:firefox": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: Browsers=Firefox karma start karma.conf.cjs --single-run",
|
|
||||||
"test:karma:server": "node bin/ssl_hotfix.js cross-env karma start karma.conf.cjs",
|
|
||||||
"test:build:version": "node ./bin/check-build-version.js",
|
|
||||||
"start": "node ./sandbox/server.js",
|
"start": "node ./sandbox/server.js",
|
||||||
"preversion": "gulp version",
|
|
||||||
"version": "npm run build && git add package.json",
|
|
||||||
"prepublishOnly": "npm run test:build:version",
|
|
||||||
"build": "gulp clear && cross-env NODE_ENV=production rollup -c -m",
|
|
||||||
"examples": "node ./examples/server.js",
|
"examples": "node ./examples/server.js",
|
||||||
"fix": "eslint --fix lib/**/*.js",
|
"fix": "eslint --fix lib/**/*.js",
|
||||||
"prepare": "husky install && npm run prepare:hooks",
|
"prepare": "husky install && npm run prepare:hooks",
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
# Test Contribution Guide
|
||||||
|
|
||||||
|
This guide explains how to contribute tests inside the `tests` directory.
|
||||||
|
It is intentionally scoped to this directory only.
|
||||||
|
|
||||||
|
## Tests Directory Layout
|
||||||
|
|
||||||
|
```text
|
||||||
|
tests/
|
||||||
|
browser/ # browser runtime tests
|
||||||
|
setup/ # shared test setup utilities
|
||||||
|
smoke/ # package-compat smoke suites (esm + cjs)
|
||||||
|
unit/ # focused unit/behavior tests
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the runtime-first layout already present in this directory:
|
||||||
|
|
||||||
|
- Put browser-runtime behavior in `tests/browser`.
|
||||||
|
- Put non-browser focused tests in `tests/unit`.
|
||||||
|
- Put packaging/compatibility smoke checks in `tests/smoke/esm/tests` and `tests/smoke/cjs/tests`.
|
||||||
|
- Reuse helpers from `tests/setup` instead of duplicating setup logic.
|
||||||
|
|
||||||
|
## File Naming Conventions
|
||||||
|
|
||||||
|
Follow the existing file patterns:
|
||||||
|
|
||||||
|
- Unit tests: `*.test.js`
|
||||||
|
- Browser tests: `*.browser.test.js`
|
||||||
|
- ESM smoke tests: `*.smoke.test.js`
|
||||||
|
- CJS smoke tests: `*.smoke.test.cjs`
|
||||||
|
|
||||||
|
When adding a new test, match the nearest existing file name pattern in the same subdirectory.
|
||||||
|
|
||||||
|
## Suite-Specific Authoring Patterns
|
||||||
|
|
||||||
|
### Unit (`tests/unit`)
|
||||||
|
|
||||||
|
- Keep tests focused on one behavior or API surface.
|
||||||
|
- For adapter/network behavior, prefer local test servers using utilities from `tests/setup/server.js`.
|
||||||
|
- Ensure server cleanup with `try/finally` so tests do not leak resources.
|
||||||
|
- Keep fixtures close to the tests that use them (see `tests/unit/adapters` for examples).
|
||||||
|
|
||||||
|
Representative files:
|
||||||
|
|
||||||
|
- `tests/unit/adapters/http.test.js`
|
||||||
|
- `tests/unit/adapters/fetch.test.js`
|
||||||
|
- `tests/unit/regression.test.js`
|
||||||
|
|
||||||
|
### Browser (`tests/browser`)
|
||||||
|
|
||||||
|
- Use local in-file `MockXMLHttpRequest` style mocks when testing request behavior.
|
||||||
|
- Replace global XHR in `beforeEach` and restore it in `afterEach`.
|
||||||
|
- Reset spies/mocks in cleanup hooks to keep tests isolated.
|
||||||
|
- Keep assertions centered on observable request/response behavior.
|
||||||
|
|
||||||
|
Representative files:
|
||||||
|
|
||||||
|
- `tests/browser/requests.browser.test.js`
|
||||||
|
- `tests/browser/adapter.browser.test.js`
|
||||||
|
- `tests/browser/defaults.browser.test.js`
|
||||||
|
|
||||||
|
### Smoke (`tests/smoke`)
|
||||||
|
|
||||||
|
- Keep ESM and CJS smoke coverage aligned for compatibility-sensitive behavior.
|
||||||
|
- If you add a new smoke scenario in one format, add the equivalent in the other format.
|
||||||
|
- Keep smoke tests small and focused on import/runtime behavior and critical request flows.
|
||||||
|
|
||||||
|
Representative files:
|
||||||
|
|
||||||
|
- `tests/smoke/esm/tests/fetch.smoke.test.js`
|
||||||
|
- `tests/smoke/cjs/tests/fetch.smoke.test.cjs`
|
||||||
|
- `tests/smoke/esm/tests/basic.smoke.test.js`
|
||||||
|
- `tests/smoke/cjs/tests/basic.smoke.test.cjs`
|
||||||
|
|
||||||
|
## Shared Setup Utilities (`tests/setup`)
|
||||||
|
|
||||||
|
Use shared helpers before introducing new setup code:
|
||||||
|
|
||||||
|
- `tests/setup/server.js`
|
||||||
|
- Server lifecycle helpers: `startHTTPServer`, `stopHTTPServer`, `stopAllTrackedHTTPServers`
|
||||||
|
- Timing helpers: `setTimeoutAsync`
|
||||||
|
- Data/stream helpers used by adapter tests
|
||||||
|
- `tests/setup/browser.setup.js`
|
||||||
|
- Browser cleanup hook (`afterEach`) for clearing test DOM state
|
||||||
|
|
||||||
|
General expectation: if a helper can be reused by multiple tests in this directory, add or extend it in `tests/setup` instead of copying setup code between test files.
|
||||||
|
|
||||||
|
## Fixtures and Test Data
|
||||||
|
|
||||||
|
- Prefer colocated fixtures near the test files that need them.
|
||||||
|
- Keep fixture names explicit and stable.
|
||||||
|
- For matrix-like scenarios, prefer concise table-driven cases inside the test file when practical.
|
||||||
|
|
||||||
|
Examples of colocated fixtures:
|
||||||
|
|
||||||
|
- `tests/unit/adapters/cert.pem`
|
||||||
|
- `tests/unit/adapters/key.pem`
|
||||||
|
- `tests/unit/adapters/axios.png`
|
||||||
|
|
||||||
|
## Contributor Checklist
|
||||||
|
|
||||||
|
Before opening a PR for tests in this directory:
|
||||||
|
|
||||||
|
- File is placed in the correct suite directory (`unit`, `browser`, or `smoke`).
|
||||||
|
- File name matches the local pattern (`*.test.js`, `*.browser.test.js`, `*.smoke.test.js`, `*.smoke.test.cjs`).
|
||||||
|
- Test setup/teardown is explicit and leaves no global/server state behind.
|
||||||
|
- Shared setup logic uses `tests/setup` helpers where possible.
|
||||||
|
- Smoke tests remain ESM/CJS consistent when behavior is format-sensitive.
|
||||||
|
- Fixtures are colocated and minimal.
|
||||||
|
- Assertions are deterministic and avoid unnecessary timing/network flakiness.
|
||||||
Reference in New Issue
Block a user