Skip to content

Commit

Permalink
feat(stark-testing): improve karma config for ng test usage
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Adapt test ci script in "package.json":
  ```
  // BEFORE
  "test-fast:ci": "cross-env CI=1 npm run ng test --code-coverage",

  // AFTER
  "test-fast:ci": "npm run ng test -- --watch=false --code-coverage",
  ```
  • Loading branch information
SuperITMan committed Sep 7, 2021
1 parent 9ced696 commit 82d0bac
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@
"test:starter:e2e": "cd starter && npm run e2e && cd ../..",
"test:ci:all": "npm run test:ci:stark-core && npm run test:ci:stark-ui && npm run test:ci:stark-rbac && npm run test:ci:starter && npm run test:ci:showcase",
"test:ci:packages": "npm run test:ci:stark-core && npm run test:ci:stark-ui && npm run test:ci:stark-rbac",
"test:ci:stark-core": "cross-env CI=true ng test stark-core --code-coverage",
"test:ci:stark-rbac": "cross-env CI=true ng test stark-rbac --code-coverage",
"test:ci:stark-ui": "cross-env CI=true ng test stark-ui --code-coverage",
"test:ci:stark-core": "ng test stark-core --watch=false --code-coverage",
"test:ci:stark-rbac": "ng test stark-rbac --watch=false --code-coverage",
"test:ci:stark-ui": "ng test stark-ui --watch=false --code-coverage",
"test:ci:showcase": "cd showcase && npm run test-fast:ci && cd ../..",
"test:ci:starter": "cd starter && npm run test-fast:ci && cd ../..",
"test:ci:coveralls:combined": "node combine-packages-coverage.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"test": "npm run lint && npm run test-fast",
"test:ci": "npm run lint && npm run test-fast:ci",
"test-fast": "npm run ng test",
"test-fast:ci": "../../node_modules/.bin/cross-env CI=1 npm run ng test -- --code-coverage",
"test-fast:ci": "ng test --watch=false --code-coverage",
"tsc": "node ../../node_modules/typescript/bin/tsc -p ./tsconfig.json",
"tslint": "node ../../node_modules/tslint/bin/tslint",
"tslint-check": "tslint-config-prettier-check ./tslint.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-rbac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test": "npm run lint && npm run test-fast",
"test:ci": "npm run lint && npm run test-fast:ci",
"test-fast": "npm run ng test",
"test-fast:ci": "../../node_modules/.bin/cross-env CI=1 npm run ng test -- --code-coverage",
"test-fast:ci": "ng test --watch=false --code-coverage",
"tsc": "node ../../node_modules/typescript/bin/tsc -p ./tsconfig.json",
"tslint": "node ../../node_modules/tslint/bin/tslint",
"tslint-check": "tslint-config-prettier-check ./tslint.json"
Expand Down
12 changes: 7 additions & 5 deletions packages/stark-testing/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Helpers
const helpers = require("./helpers");
const ciDetect = require("@npmcli/ci-detect");
const isCI = process.argv.indexOf("--watch=false") > -1 || !!ciDetect();

const rawKarmaConfig = {
// base path that will be used to resolve all patterns (e.g. files, exclude)
Expand Down Expand Up @@ -30,7 +31,7 @@ const rawKarmaConfig = {
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// https://www.npmjs.com/package/karma-junit-reporter
// https://www.npmjs.com/package/karma-spec-reporter
reporters: !!ciDetect() ? ["mocha", "progress"] : ["mocha", "progress", "kjhtml"],
reporters: isCI ? ["mocha", "progress"] : ["mocha", "progress", "kjhtml"],

// web server port
port: 9876,
Expand All @@ -54,14 +55,14 @@ const rawKarmaConfig = {

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: !!ciDetect() ? ["ChromeHeadlessNoSandbox"] : ["Chrome"],
browsers: isCI ? ["ChromeHeadlessNoSandbox"] : ["Chrome"],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: !!ciDetect(),
singleRun: isCI,

// If true, tests restart automatically if a file is changed
restartOnFileChange: !ciDetect(),
restartOnFileChange: !isCI,

// Timeout settings
browserNoActivityTimeout: 30000,
Expand Down Expand Up @@ -94,5 +95,6 @@ module.exports = {
default: function (config) {
config.set(rawKarmaConfig);
},
rawKarmaConfig: rawKarmaConfig
rawKarmaConfig: rawKarmaConfig,
isCITest: isCI
};
2 changes: 1 addition & 1 deletion packages/stark-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"test": "npm run lint && npm run test-fast",
"test:ci": "npm run lint && npm run test-fast:ci",
"test-fast": "npm run ng test",
"test-fast:ci": "../../node_modules/.bin/cross-env CI=1 npm run ng test -- --code-coverage",
"test-fast:ci": "ng test --watch=false --code-coverage",
"tsc": "node ../../node_modules/typescript/bin/tsc -p ./tsconfig.json",
"tslint": "node ../../node_modules/tslint/bin/tslint",
"tslint-check": "tslint-config-prettier-check ./tslint.json"
Expand Down
15 changes: 0 additions & 15 deletions showcase/karma.conf.ci.js

This file was deleted.

2 changes: 1 addition & 1 deletion showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"test": "npm run lint && npm run test-fast",
"test:ci": "npm run lint && npm run test-fast:ci",
"test-fast": "npm run ng test",
"test-fast:ci": "cross-env CI=1 npm run ng test --code-coverage",
"test-fast:ci": "npm run ng -- test --watch=false --code-coverage",
"tsc": "tsc",
"tslint": "tslint",
"tslint-check": "tslint-config-prettier-check ./tslint.json",
Expand Down
15 changes: 0 additions & 15 deletions starter/karma.conf.ci.js

This file was deleted.

2 changes: 1 addition & 1 deletion starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"test": "npm run lint && npm run test-fast",
"test:ci": "npm run lint && npm run test-fast:ci",
"test-fast": "npm run ng test",
"test-fast:ci": "cross-env CI=1 npm run ng test --code-coverage",
"test-fast:ci": "npm run ng test -- --watch=false --code-coverage",
"tsc": "tsc",
"tslint": "tslint",
"tslint-check": "tslint-config-prettier-check ./tslint.json",
Expand Down

0 comments on commit 82d0bac

Please sign in to comment.