Skip to content

Commit

Permalink
chore: use jest projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahed Ahmed committed Jan 25, 2022
1 parent aa11a81 commit 0d413ae
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 56 deletions.
27 changes: 3 additions & 24 deletions .circleci/config.yml
Expand Up @@ -250,21 +250,9 @@ jobs:
- run:
name: Configuring Snyk CLI
command: node ./bin/snyk config set "api=$env:SNYK_API_KEY"
- run:
name: Running packages unit tests
command: npm run test:packages-unit -- --ci
- run:
name: Running packages acceptance tests
command: npm run test:packages-acceptance -- --ci
- run:
name: Running root tests
command: npm run test:jest -- --ci
- run:
name: Running unit tests
command: npm run test:jest-unit -- --ci
- run:
name: Running acceptance tests
command: npm run test:jest-acceptance -- --ci
command: npm run test:acceptance
test-linux:
<<: *defaults
docker:
Expand All @@ -285,23 +273,14 @@ jobs:
- run:
name: Configuring Snyk CLI
command: node ./bin/snyk config set "api=${SNYK_API_KEY}"
- run:
name: Running packages unit tests
command: npm run test:packages-unit -- --ci
- run:
name: Running packages acceptance tests
command: npm run test:packages-acceptance -- --ci
- run:
name: Running root tests
command: npm run test:jest -- --ci
- run:
name: Running unit tests
command: npm run test:jest-unit -- --ci
command: npm run test:unit
- aws-cli/install:
version: << parameters.aws_version >>
- run:
name: Running acceptance tests
command: npm run test:jest-acceptance -- --ci
command: npm run test:acceptance

test-tap:
<<: *defaults
Expand Down
22 changes: 6 additions & 16 deletions jest.config.js
@@ -1,16 +1,6 @@
module.exports = {
preset: 'ts-jest',
testMatch: [
'<rootDir>/test/*.spec.ts',
'<rootDir>/test/iac-unit-tests/*.spec.ts',
'<rootDir>/packages/**/test/**/*.spec.ts',
'<rootDir>/test/jest/unit/**/*.spec.ts',
'<rootDir>/test/jest/acceptance/**/*.spec.ts',
],
modulePathIgnorePatterns: [
'<rootDir>/test/.*fixtures/*',
'<rootDir>/packages/.+/test/.*fixtures/*',
'<rootDir>/test/acceptance/*',
'<rootDir>/test/acceptance/workspaces/*', // to avoid `jest-haste-map: Haste module naming collision` errors
],
};
const { createJestConfig } = require('./test/createJestConfig');

module.exports = createJestConfig({
displayName: 'snyk',
projects: ['<rootDir>', '<rootDir>/packages/*'],
});
9 changes: 3 additions & 6 deletions package.json
Expand Up @@ -42,12 +42,9 @@
"build-cli:dev": "node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js --config webpack.dev.ts",
"build-cli:prod": "node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js --config webpack.prod.ts",
"watch": "npm run build-cli:dev -- --watch",
"test": "npm run test:jest && test:packages-unit && test:packages-acceptance && npm run test:tap",
"test:jest": "jest --runInBand \"/test/[^/]+\\.spec\\.ts\"",
"test:jest-unit": "jest --runInBand \"/test/jest/unit/((.+)/)*[^/]+\\.spec\\.ts\"",
"test:jest-acceptance": "jest --runInBand \"/test/jest/acceptance/((.+)/)*[^/]+\\.spec\\.ts\"",
"test:packages-unit": "jest --runInBand \"/packages/(.+)/test/unit/((.+)/)*[^/]+\\.spec\\.ts\"",
"test:packages-acceptance": "jest --runInBand \"/packages/(.+)/test/acceptance/((.+)/)*[^/]+\\.spec\\.ts\"",
"test": "npm run test:unit && test:acceptance && npm run test:tap",
"test:unit": "jest --runInBand --testPathPattern '/test(/jest)?/unit/'",
"test:acceptance": "jest --runInBand --testPathPattern '/test(/jest)?/acceptance/'",
"test:tap": "tap -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register test/tap/*.test.* ",
"test:smoke": "./scripts/run-smoke-tests-locally.sh"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/cli-alert/jest.config.js
@@ -0,0 +1,3 @@
const { createJestConfig } = require('../../test/createJestConfig');

module.exports = createJestConfig({ displayName: '@snyk/cli-alert' });
6 changes: 3 additions & 3 deletions packages/snyk-fix/jest.config.js
@@ -1,3 +1,3 @@
module.exports = {
preset: 'ts-jest',
};
const { createJestConfig } = require('../../test/createJestConfig');

module.exports = createJestConfig({ displayName: '@snyk/fix' });
10 changes: 3 additions & 7 deletions packages/snyk-protect/jest.config.js
@@ -1,7 +1,3 @@
module.exports = {
preset: 'ts-jest',
testMatch: [
'<rootDir>/test/**/*.spec.ts',
'<rootDir>\\test\\**\\*.spec.ts', // for Windows
],
};
const { createJestConfig } = require('../../test/createJestConfig');

module.exports = createJestConfig({ displayName: '@snyk/protect' });
25 changes: 25 additions & 0 deletions test/createJestConfig.js
@@ -0,0 +1,25 @@
const createJestConfig = (config) => {
const ignorePatterns = [
'/node_modules/',
'/dist/',
'/test/fixtures/',
'<rootDir>/test/acceptance/workspaces/',
'<rootDir>/test/tap/',
'<rootDir>/packages/',
'<rootDir>/pysrc/',
];

return {
preset: 'ts-jest',
testRegex: '\\.spec\\.ts$',
testPathIgnorePatterns: [...ignorePatterns],
modulePathIgnorePatterns: [...ignorePatterns],
coveragePathIgnorePatterns: [...ignorePatterns],
transformIgnorePatterns: [...ignorePatterns],
...config,
};
};

module.exports = {
createJestConfig,
};

0 comments on commit 0d413ae

Please sign in to comment.