Skip to content

Commit 896bfcb

Browse files
authored
feat: adding smoke tests for multiple .net versions (#209)
1 parent 603cc93 commit 896bfcb

File tree

3 files changed

+128
-44
lines changed

3 files changed

+128
-44
lines changed

.circleci/config.yml

Lines changed: 86 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ orbs:
66
prodsec: snyk/[email protected]
77

88
defaults: &defaults
9-
parameters:
9+
parameters: &default_parameters_list
1010
node_version:
1111
type: string
12-
default: ''
12+
default: ""
1313
working_directory: ~/snyk-nuget-plugin
1414

15+
defaults_test: &defaults_test
16+
<<: *defaults
17+
parameters:
18+
<<: *default_parameters_list
19+
test_type:
20+
type: enum
21+
enum: [ "unit", "smoke" ]
22+
dotnet_version:
23+
type: string
24+
1525
matrix_unix_node_version: &matrix_unix_node_version
16-
node_version: ["16.20", "18.16", "20.3"]
26+
node_version: [ "16.20", "18.16", "20.3" ]
1727

1828
matrix_windows_node_version: &matrix_windows_node_version
19-
node_version: ["16.20.0", "18.16.0", "20.3.1"]
29+
node_version: [ "16.20.0", "18.16.0", "20.3.1" ]
2030

21-
windows_defaults: &windows_defaults
22-
environment:
23-
npm_config_loglevel: silent
24-
executor:
25-
name: win/default
26-
shell: bash
31+
matrix_dotnet_version: &matrix_dotnet_version
32+
dotnet_version: [ "8.0", "7.0", "6.0" ]
2733

2834
filters_branches_only_main: &filters_branches_only_main
2935
filters:
@@ -64,37 +70,36 @@ commands:
6470
parameters:
6571
os:
6672
type: enum
67-
enum: ['unix', 'windows']
73+
enum: [ "unix", "windows" ]
6874
dotnet_version:
6975
type: string
70-
default: '8.0'
7176
steps:
7277
- restore_cache:
7378
name: Restore Dotnet executable
7479
keys:
7580
- dotnet-cli-{{ arch }}-{{<< parameters.dotnet_version >>}}-v3
7681
- when:
7782
condition:
78-
equal: [ 'unix', << parameters.os >> ]
83+
equal: [ "unix", << parameters.os >> ]
7984
steps:
80-
- run:
81-
name: Download and install dotnet
82-
command: |
83-
if ! command -v dotnet &> /dev/null
84-
then
85-
echo "dotnet could not be found, downloading and installing"
86-
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel << parameters.dotnet_version >> --install-dir ~/.local/apps/dotnet
87-
ln -s ~/.local/apps/dotnet/dotnet ~/.local/bin/
88-
exit
89-
fi
90-
- save_cache:
91-
key: dotnet-cli-{{ arch }}-{{<< parameters.dotnet_version >>}}-v3
92-
paths:
93-
- ~/.local/apps/dotnet
94-
- ~/.local/bin/dotnet
85+
- run:
86+
name: Download and install dotnet
87+
command: |
88+
if ! command -v dotnet &> /dev/null
89+
then
90+
echo "dotnet could not be found, downloading and installing"
91+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel << parameters.dotnet_version >> --install-dir ~/.local/apps/dotnet
92+
ln -s ~/.local/apps/dotnet/dotnet ~/.local/bin/
93+
exit
94+
fi
95+
- save_cache:
96+
key: dotnet-cli-{{ arch }}-{{<< parameters.dotnet_version >>}}-v3
97+
paths:
98+
- ~/.local/apps/dotnet
99+
- ~/.local/bin/dotnet
95100
- when:
96101
condition:
97-
equal: [ 'windows', << parameters.os >> ]
102+
equal: [ "windows", << parameters.os >> ]
98103
steps:
99104
- run:
100105
name: Download and install dotnet
@@ -134,40 +139,45 @@ jobs:
134139
command: npm run lint
135140

136141
test-windows:
142+
<<: *defaults_test
137143
environment:
138-
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
139-
<<: *defaults
140-
<<: *windows_defaults
144+
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
145+
npm_config_loglevel: silent
146+
executor:
147+
name: win/default
148+
shell: bash
141149
steps:
142150
- run: git config --global core.autocrlf false
143151
- checkout
144152
- install_dotnet:
145-
os: 'windows'
153+
os: "windows"
154+
dotnet_version: << parameters.dotnet_version >>
146155
- show_dotnet_version
147156
- node/install
148157
- node_install_packages
149158
- show_node_version
150159
- run:
151160
name: Run tests
152-
command: npm test
161+
command: npm run test:<< parameters.test_type >>
153162
shell: bash.exe
154163

155164
test-unix:
165+
<<: *defaults_test
156166
environment:
157-
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
158-
<<: *defaults
167+
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
159168
docker:
160169
- image: cimg/node:<< parameters.node_version >>
161170
steps:
162171
- checkout
163172
- install_dotnet:
164-
os: 'unix'
173+
os: "unix"
174+
dotnet_version: << parameters.dotnet_version >>
165175
- show_dotnet_version
166176
- node_install_packages
167177
- show_node_version
168178
- run:
169179
name: Run tests
170-
command: npm test
180+
command: npm run test:<< parameters.test_type >>
171181

172182
release:
173183
<<: *defaults
@@ -195,15 +205,31 @@ workflows:
195205
- lint:
196206
name: Lint
197207
context: nodejs-install
198-
node_version: '16.20'
208+
node_version: "16.20"
199209
<<: *filters_branches_ignore_main
200210

201211
- test-unix:
202212
matrix:
203-
alias: test-unix
213+
alias: test-unix-unit
204214
parameters:
205215
<<: *matrix_unix_node_version
206-
name: Unix Tests for Node=<< matrix.node_version >>
216+
test_type: [ "unit" ]
217+
dotnet_version: [ "8.0" ]
218+
name: Unix Unit Tests for Node=<< matrix.node_version >>
219+
context: nodejs-install
220+
node_version: "<< matrix.node_version >>"
221+
requires:
222+
- Lint
223+
<<: *filters_branches_ignore_main
224+
225+
- test-unix:
226+
matrix:
227+
alias: test-unix-smoke
228+
parameters:
229+
<<: *matrix_dotnet_version
230+
test_type: [ "smoke" ]
231+
node_version: [ "lts" ]
232+
name: Unix Smoke Tests for Node=<< matrix.node_version >>-Dotnet=<< matrix.dotnet_version >>
207233
context: nodejs-install
208234
node_version: "<< matrix.node_version >>"
209235
requires:
@@ -212,10 +238,26 @@ workflows:
212238

213239
- test-windows:
214240
matrix:
215-
alias: test-windows
241+
alias: test-windows-unit
216242
parameters:
217243
<<: *matrix_windows_node_version
218-
name: Windows Tests for Node=<< matrix.node_version >>
244+
test_type: [ "unit" ]
245+
dotnet_version: [ "8.0" ]
246+
name: Windows Unit Tests for Node=<< matrix.node_version >>
247+
context: nodejs-install
248+
node_version: "<< matrix.node_version >>"
249+
requires:
250+
- Lint
251+
<<: *filters_branches_ignore_main
252+
253+
- test-windows:
254+
matrix:
255+
alias: test-windows-smoke
256+
parameters:
257+
<<: *matrix_dotnet_version
258+
test_type: [ "smoke" ]
259+
node_version: [ "lts" ]
260+
name: Windows Smoke Tests for Node=<< matrix.node_version >>-Dotnet=<< matrix.dotnet_version >>
219261
context: nodejs-install
220262
node_version: "<< matrix.node_version >>"
221263
requires:
@@ -225,5 +267,5 @@ workflows:
225267
- release:
226268
name: Release
227269
context: nodejs-app-release
228-
node_version: 'lts'
270+
node_version: "lts"
229271
<<: *filters_branches_only_main

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"test": "npm run test:unit",
88
"test:unit": "jest --coverage --runInBand",
9+
"test:smoke": "jest --coverage --silent=false --detectOpenHandles --testMatch **/*.spec.smoke.ts --bail",
910
"lint": "npm run lint:prettier && npm run lint:eslint",
1011
"lint:eslint": "eslint -c .eslintrc '{lib,test}/**/*.ts'",
1112
"lint:prettier": "prettier --check '{lib,test}/**/*.{ts,csproj,json}' --log-level 'warn'",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import * as plugin from '../../lib';
5+
import * as dotnet from '../../lib/nuget-parser/cli/dotnet';
6+
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
7+
8+
describe('generating v2 depgraphs using all supported .NET SDKs', () => {
9+
it.each([
10+
{
11+
description: 'parse dotnet 6.0',
12+
projectPath: './test/fixtures/dotnetcore/dotnet_6',
13+
},
14+
])(
15+
'succeeds given a project file and returns a single dependency graph for single-targetFramework projects: $description',
16+
async ({ projectPath }) => {
17+
// Run a dotnet restore beforehand, in order to be able to supply a project.assets.json file
18+
const manifestFilePath = await dotnet.restore(projectPath);
19+
20+
const result = await plugin.inspect(projectPath, manifestFilePath, {
21+
'dotnet-runtime-resolution': true,
22+
});
23+
24+
if (!pluginApi.isMultiResult(result)) {
25+
throw new Error('expected a multiResult response from inspection');
26+
}
27+
28+
expect(result.scannedProjects.length).toEqual(1);
29+
30+
const expectedGraph = JSON.parse(
31+
fs.readFileSync(
32+
path.resolve(projectPath, 'expected_depgraph.json'),
33+
'utf-8',
34+
),
35+
);
36+
expect(result.scannedProjects[0].depGraph?.toJSON()).toEqual(
37+
expectedGraph.depGraph,
38+
);
39+
},
40+
);
41+
});

0 commit comments

Comments
 (0)