Skip to content

Commit 9683252

Browse files
committedJun 14, 2024
add test for yarn package manager
1 parent 39434c0 commit 9683252

File tree

8 files changed

+1072
-536
lines changed

8 files changed

+1072
-536
lines changed
 

‎tests/integration/__snapshots__/index.test.js.snap

+946-534
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*
2+
!/.gitignore
3+
!/.gitattributes
4+
!/README.md
5+
!/package.json
6+
!/package-lock.json
7+
!/webpack.config.js
8+
!/src
9+
!/src/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test: is copied file's package detected
2+
3+
This setup is intended to create reproducible results (SBoM).
4+
It might install outdated, unmaintained or vulnerable components, for showcasing purposes.
5+
6+
Importing `libphonenumber-js/max` should not result in `libphonenumber-js/max` being added to the SBoM without any version.
7+
Instead `libphonenumber-js` should be added with the correct version.
8+
9+
Importing `luxon` should result in `luxon` being added to the SBoM.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@cyclonedx-weboack-plugin-tests/improvement-issue-1284-yarn",
3+
"description": "example to verify issue 1284 with yarn",
4+
"private": true,
5+
"main": "index.html",
6+
"scripts": {
7+
"prebuild": "node -r fs -e 'fs.rmSync(\"dist\",{recursive:true,force:true})'",
8+
"build": "webpack build"
9+
},
10+
"dependencies": {
11+
"libphonenumber-js": "^1.9.19",
12+
"luxon": "3.4.4"
13+
},
14+
"devDependencies": {
15+
"@cyclonedx/webpack-plugin": "portal:../../..",
16+
"bootstrap": "^5.1.3",
17+
"webpack": "^5.72.0",
18+
"webpack-cli": "^4.9.2"
19+
},
20+
"engines": {
21+
"node": ">=14.0.0",
22+
"yarn": ">=4.3.0"
23+
},
24+
"packageManager": "yarn@4.3.0"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { parsePhoneNumberFromString } = require("libphonenumber-js/max");
2+
const { DateTime } = require("luxon");
3+
4+
console.log(DateTime.now());
5+
6+
console.log(parsePhoneNumberFromString("+12133734253", "US"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*!
2+
This file is part of CycloneDX Webpack plugin.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
const path = require('path')
21+
const { CycloneDxWebpackPlugin } = require('@cyclonedx/webpack-plugin')
22+
23+
module.exports = {
24+
entry: './src/index.js',
25+
output: {
26+
path: path.resolve(__dirname, 'dist'),
27+
filename: 'bundle.js'
28+
},
29+
plugins: [
30+
new CycloneDxWebpackPlugin(
31+
{
32+
outputLocation: '.bom',
33+
reproducibleResults: true
34+
}
35+
)
36+
]
37+
}

‎tests/integration/index.test.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ const testSetups = [
137137
file: 'dist/.well-known/sbom'
138138
}
139139
]
140+
},
141+
{
142+
dir: 'improvement-issue-1284-yarn',
143+
packageManager: 'yarn',
144+
purpose: 'functional: verify enhanced package.json finder with yarn pkg manager',
145+
results: [ // paths relative to `dir`
146+
{
147+
format: 'xml',
148+
file: 'dist/.bom/bom.xml'
149+
},
150+
{
151+
format: 'json',
152+
file: 'dist/.bom/bom.json'
153+
},
154+
{
155+
format: 'json',
156+
file: 'dist/.well-known/sbom'
157+
}
158+
]
140159
}
141160
]
142161

@@ -150,10 +169,10 @@ try {
150169
}
151170

152171
describe('integration', () => {
153-
testSetups.forEach(({ purpose, dir, results }) => {
172+
testSetups.forEach(({ purpose, dir, results, packageManager }) => {
154173
describe(purpose, () => {
155174
const built = spawnSync(
156-
'npm', ['run', 'build'], {
175+
packageManager ?? 'npm', ['run', 'build'], {
157176
cwd: path.resolve(module.path, dir),
158177
stdio: ['ignore', 'pipe', 'pipe'],
159178
encoding: 'utf8',

‎tests/integration/setup.js

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const path = require('path');
3434
'improvement-issue-1284'
3535
]
3636

37+
const REQUIRES_YARN_INSTALL = [
38+
'improvement-issue-1284-yarn'
39+
]
40+
3741
console.warn(`
3842
WILL SETUP INTEGRATION TEST BEDS
3943
THAT MIGHT CONTAIN OUTDATED VULNERABLE PACKAGES
@@ -57,4 +61,19 @@ const path = require('path');
5761
console.error(done)
5862
}
5963
}
64+
65+
for (const DIR of REQUIRES_YARN_INSTALL) {
66+
console.log('>>> setup with yarn:', DIR)
67+
done = spawnSync(
68+
'yarn', ['install', '--immutable'], {
69+
cwd: path.resolve(__dirname, DIR),
70+
stdio: 'inherit',
71+
shell: true
72+
}
73+
)
74+
if (done.status !== 0) {
75+
++process.exitCode
76+
console.error(done)
77+
}
78+
}
6079
})()

0 commit comments

Comments
 (0)