Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: test node21 #1243

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ jobs:
os: [ "ubuntu-latest" ]
node-version:
# action based on https://github.com/actions/node-versions/releases
# see also: https://nodejs.org/en/about/releases/
- "20" # current
- "18" # active LTS
# see also: https://nodejs.org/en/about/previous-releases
- "21" # current
- "20" # active LTS
- "18"
- '16'
- "14"
- "14.0.0" # lowest supported
steps:
- name: Checkout
# see https://github.com/actions/checkout
Expand All @@ -108,12 +110,30 @@ jobs:
shell: bash
run: |
set -ex
## dont install all the dev-packages, especially since some are not runnable on node 14.0.0
npm i --ignore-scripts --omit=peer --omit=dev --only=prod --loglevel=silly
dep_constraints=''
dev_requirements='jest jest-junit imurmurhash fast-glob'
# as long as npm cannot auto-resolve engine-constraints, we need to help here
case '${{ matrix.node-version }}' in
'14')
dep_constraints='normalize-package-data@^5'
;;
'14.0.0')
dep_constraints='normalize-package-data@^3'
dev_requirements='jest@^26 jest-junit imurmurhash fast-glob'
# cannot run snapshot-compare with old versions ...
rm -rf tests/integration/__snapshots__/
;;
esac
## !! dont install all the dev-packages, especially since some are not runnable on node 14.0.0
if [[ -n "$dep_constraints" ]]
then
npm add --ignore-scripts --omit=peer --omit=dev --only=prod --production --loglevel=silly --save $dep_constraints
fi
npm i --ignore-scripts --omit=peer --omit=dev --only=prod --production --loglevel=silly
## rebuild deps for which scripts were ignored, or partially installed - since "ignore-scripts" was used
npm rebuild --loglevel=silly libxmljs2 || npm uninstall --no-save libxmljs2
## install the needed dev-deps
npm i --no-save jest jest-junit
npm i --ignore-scripts --loglevel=silly --no-save $dev_requirements
- name: fetch build artifact
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v3
Expand All @@ -123,9 +143,7 @@ jobs:
- name: setup test beds
run: npm run setup-tests
- name: test
run: >
npm run test:jest --
--ci
run: npm run test:jest
env:
JEST_JUNIT_OUTPUT_DIR: ${{ env.REPORTS_DIR }}/${{ matrix.os }}_node${{ matrix.node-version }}
- name: collect coverage
Expand Down
221 changes: 118 additions & 103 deletions tests/integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,121 +25,136 @@ const { describe, expect, it } = require('@jest/globals')

const { version: thisVersion } = require('../../package.json')

describe('integration', () => {
describe.each(
[
// region functional
const testSetups = [
// region functional
{
dir: 'webpack5-vue2',
purpose: 'functional: webpack5 with vue2',
results: [ // paths relative to `dir`
{
dir: 'webpack5-vue2',
purpose: 'functional: webpack5 with vue2',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
]
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
dir: 'webpack5-angular13',
purpose: 'functional: webpack5 with angular13',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
]
format: 'json',
file: 'dist/.bom/bom.json'
},
{
dir: 'webpack5-react18',
purpose: 'functional: webpack5 with react18',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
]
format: 'json',
file: 'dist/.well-known/sbom'
}
]
},
{
dir: 'webpack5-angular13',
purpose: 'functional: webpack5 with angular13',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
// endregion functional
// region regression
{
dir: 'regression-issue745',
purpose: 'regression: issue#745',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
]
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
// endregion regression
]
)('$purpose', ({ dir, results }) => {
const built = spawnSync(
'npm', ['run', 'build'], {
cwd: path.resolve(__dirname, dir),
stdio: ['ignore', 'pipe', 'pipe'],
encoding: 'utf8',
shell: true,
env: {
PATH: process.env.PATH,
CI: '1'
}
},
{
dir: 'webpack5-react18',
purpose: 'functional: webpack5 with react18',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
)
let skipTests = false
try {
expect(built.status).toBe(0)
} catch (err) {
if (/should not be used for production|Angular CLI requires a minimum|does not support Node\.js v/.test(built.stderr.toString())) {
skipTests = true
} else {
console.log(built, '\n')
throw err
]
},
// endregion functional
// region regression
{
dir: 'regression-issue745',
purpose: 'regression: issue#745',
results: [ // paths relative to `dir`
{
format: 'xml',
file: 'dist/.bom/bom.xml'
},
{
format: 'json',
file: 'dist/.bom/bom.json'
},
{
format: 'json',
file: 'dist/.well-known/sbom'
}
}
]
}
// endregion regression
]

(skipTests
? it.skip
: it
).each(results)('generated $format file: $file', ({ format, file }) => {
const resultFile = path.resolve(__dirname, dir, file)
const resultBuffer = fs.readFileSync(resultFile)
expect(resultBuffer).toBeInstanceOf(Buffer)
expect(resultBuffer.length).toBeGreaterThan(0)
const resultReproducible = makeReproducible(format, resultBuffer.toString())
expect(resultReproducible).toMatchSnapshot()
// for testing purposes, some outdated jest version must be used.
// this version has a different format for snapshots ...
let compareSnapshots
try {
compareSnapshots = Number(require('jest/package.json').version.split('.')[0]) >= 29
} catch {
compareSnapshots = null
}

describe('integration', () => {
testSetups.forEach(({ purpose, dir, results }) => {
describe(purpose, () => {
const built = spawnSync(
'npm', ['run', 'build'], {
cwd: path.resolve(module.path, dir),
stdio: ['ignore', 'pipe', 'pipe'],
encoding: 'utf8',
shell: true,
env: {
PATH: process.env.PATH,
CI: '1'
}
}
)
let skipTests = false
try {
expect(built.status).toBe(0)
} catch (err) {
if (/should not be used for production|Angular CLI requires a minimum|does not support Node\.js v/.test(built.stderr.toString())) {
skipTests = true
} else {
console.log(built, '\n')
throw err
}
}

results.forEach(({ format, file }) => {
(skipTests
? it.skip
: it
)(`generated ${format} file: ${file}`, () => {
const resultFile = path.resolve(module.path, dir, file)
const resultBuffer = fs.readFileSync(resultFile)
expect(resultBuffer).toBeInstanceOf(Buffer)
expect(resultBuffer.length).toBeGreaterThan(0)
const resultReproducible = makeReproducible(format, resultBuffer.toString())
if (compareSnapshots) {
expect(resultReproducible).toMatchSnapshot()
}
})
})
})
})
})
Expand Down