Skip to content

Commit

Permalink
tests: yarn setup
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Jun 17, 2024
1 parent 188598c commit 898776d
Show file tree
Hide file tree
Showing 13 changed files with 3,619 additions and 5 deletions.
399 changes: 399 additions & 0 deletions tests/integration/__snapshots__/index.test.js.snap

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions tests/integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ const testSetups = [
}
]
},
{
dir: 'webpack5-vue2-yarn',
purpose: 'functional: webpack5 with vue2 in yarn setup',
packageManager: 'yarn',
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'
}
]
},
{
dir: 'webpack5-angular13',
purpose: 'functional: webpack5 with angular13',
Expand Down Expand Up @@ -132,10 +151,10 @@ try {
}

describe('integration', () => {
testSetups.forEach(({ purpose, dir, results }) => {
testSetups.forEach(({ purpose, dir, packageManager, results }) => {
describe(purpose, () => {
const built = spawnSync(
'npm', ['run', 'build'], {
packageManager ?? 'npm', ['run', 'build'], {
cwd: path.resolve(module.path, dir),
stdio: ['ignore', 'pipe', 'pipe'],
encoding: 'utf8',
Expand Down
38 changes: 36 additions & 2 deletions tests/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ const path = require('path');
// endregion regression tests
]

const REQUIRES_YARN_INSTALL = [
// region functional tests
'webpack5-vue2-yarn',

Check failure on line 38 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test standard

Unexpected trailing comma
// endregion functional tests
// region regression tests
// endregion regression tests
]

console.warn(`
WILL SETUP INTEGRATION TEST BEDS
THAT MIGHT CONTAIN OUTDATED VULNERABLE PACKAGES
FOR SHOWCASING AND TESTING PURPOSES ONLY.
`)

process.exitCode = 0
let done

for (const DIR of REQUIRES_NPM_INSTALL) {
console.log('>>> setup with NPM:', DIR)
done = spawnSync(
const done = spawnSync(
'npm', ['ci'], {
cwd: path.resolve(__dirname, DIR),
stdio: 'inherit',
Expand All @@ -56,4 +63,31 @@ const path = require('path');
console.error(done)
}
}

for (const DIR of REQUIRES_YARN_INSTALL) {
console.log('>>> setup with YARN:', DIR)
let done = spawnSync(
'yarn', ['set', 'version', 'stable'], {
cwd: path.resolve(__dirname, DIR),
stdio: 'inherit',
shell: true
}
)
if (done.status !== 0) {
++process.exitCode
console.error(done)
continue
}
done = spawnSync(
'yarn', ['install', '--immutable'], {
cwd: path.resolve(__dirname, DIR),
stdio: 'inherit',
shell: true
}
)
if (done.status !== 0) {
++process.exitCode
console.error(done)
}
}
})()
1 change: 1 addition & 0 deletions tests/integration/webpack5-vue2-yarn/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
** linguist-vendored
10 changes: 10 additions & 0 deletions tests/integration/webpack5-vue2-yarn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*
!/.gitignore
!/.gitattributes
!/README.md
!/.yarnrc.yml
!/package.json
!/yarn.lock
!/webpack.config.js
!/src
!/src/*
1 change: 1 addition & 0 deletions tests/integration/webpack5-vue2-yarn/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-4.3.0.cjs
4 changes: 4 additions & 0 deletions tests/integration/webpack5-vue2-yarn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test: Vue.js bundled with webpack5 in a yarn setup

This setup is intended to create reproducible results (SBoM).
It might install outdated, unmaintained or vulnerable components, for showcasing purposes.
46 changes: 46 additions & 0 deletions tests/integration/webpack5-vue2-yarn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@cyclonedx-webpack-plugin-tests/example-webpack5-vue2-yarn",
"description": "example setup witch Vue2 in WebPack5 with yarn setup",
"private": true,
"homepage": "https://github.com/CycloneDX/cyclonedx-webpack-plugin/tree/master/tests/integration/webpack5-vue2#readme",
"copyright": "Copyright OWASP Foundation",
"license": "Apache-2.0",
"author": {
"name": "Jan Kowalleck",
"email": "jan.kowalleck@gmail.com"
},
"contributors": [
{
"name": "Jan Kowalleck",
"email": "jan.kowalleck@gmail.com"
}
],
"repository": {
"type": "git",
"url": "git+https://github.com/CycloneDX/cyclonedx-webpack-plugin.git",
"directory": "tests/integration/webpack5-vue2-yarn"
},
"bugs": {
"url": "https://github.com/CycloneDX/cyclonedx-webpack-plugin/issues"
},
"main": "index.html",
"scripts": {
"prebuild:node": "node -r fs -e 'fs.rmSync(\"dist\",{recursive:true,force:true})'",
"build": "webpack build"
},
"dependencies": {
"vue": "^2.6.14"
},
"devDependencies": {
"@cyclonedx/webpack-plugin": "portal:../../..",
"html-inline-script-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^5.5.0",
"webpack": "^5",
"webpack-cli": "^5"
},
"engines": {
"node": ">=18",
"yarn": ">=4"
},
"packageManager": "yarn@4.3.0"
}
15 changes: 15 additions & 0 deletions tests/integration/webpack5-vue2-yarn/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Example</title>
<meta charset="utf-8" />
</head>

<body>
<div id="app">
<!-- example /-->
</div>
</body>

</html>
14 changes: 14 additions & 0 deletions tests/integration/webpack5-vue2-yarn/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Vue from 'vue'

const app = new Vue({
data: {},
methods: {}
})

document.addEventListener(
'DOMContentLoaded',
function () {
app.$mount('#app')
},
false
)
37 changes: 37 additions & 0 deletions tests/integration/webpack5-vue2-yarn/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin')

const { CycloneDxWebpackPlugin } = require('@cyclonedx/webpack-plugin')

module.exports = {
entry: './src/index.js',
// Webpack noise constrained to ALL details - for debugging purposes
stats: 'detailed',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new HtmlInlineScriptPlugin(),
new CycloneDxWebpackPlugin(
{
specVersion: '1.6',
outputLocation: '.bom',
reproducibleResults: true,
validateResults: true
}
)
],
externals: {
// vue: 'Vue'
},
resolve: {
alias: {
vue$: 'vue/dist/vue.esm.js'
}
}
}
Loading

0 comments on commit 898776d

Please sign in to comment.