Skip to content

Commit 9e876ce

Browse files
QuantariusRayQ
authored and
Q
committed
remove spectator and replace with karma/jasmine
1 parent 06c1e84 commit 9e876ce

37 files changed

+866
-2963
lines changed

.eslintrc.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"overrides": [
77
{
8-
"plugins": ["@typescript-eslint", "jest", "cypress"],
8+
"plugins": ["@typescript-eslint", "cypress"],
99
"parser": "@typescript-eslint/parser",
1010
"files": [
1111
"*.ts"
@@ -18,23 +18,18 @@
1818
"createDefaultProgram": true
1919
},
2020
"env": {
21-
"cypress/globals": true,
22-
"jest/globals": true
21+
"cypress/globals": true
2322
},
2423
"extends": [
2524
"plugin:prettier/recommended",
2625
"plugin:@angular-eslint/ng-cli-compat",
2726
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
2827
"plugin:@angular-eslint/template/process-inline-templates",
29-
"plugin:cypress/recommended",
30-
"plugin:jest/recommended",
31-
"plugin:jest/style"
28+
"plugin:cypress/recommended"
3229
],
3330

3431
"rules": {
3532
"max-len": ["error", { "code": 250 }],
36-
"jest/no-large-snapshots": ["warn", { "maxSize": 12, "inlineMaxSize": 6 }],
37-
"jest/no-jasmine-globals": "off",
3833
"quotes": [1, "single", { "allowTemplateLiterals": true }],
3934
"@angular-eslint/component-selector": [
4035
"error",

angular.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,12 @@
106106
}
107107
},
108108
"test": {
109-
"builder": "@angular-builders/jest:run",
109+
"builder": "@angular-devkit/build-angular:karma",
110110
"options": {
111-
"polyfills": ["src/polyfills.ts"],
111+
"main": "src/test.ts",
112+
"polyfills": "src/polyfills.ts",
112113
"tsConfig": "tsconfig.spec.json",
113-
"assets": [
114-
"src/favicon.ico",
115-
"src/assets"
116-
],
117-
"scripts": []
114+
"karmaConfig": "karma.conf.js"
118115
}
119116
},
120117
"lint": {

cypress/support/component.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,46 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands'
17+
import './commands';
1818

1919
// Alternatively you can use CommonJS syntax:
2020
// require('./commands')
2121

22-
import { mount } from 'cypress/angular'
22+
import { mount, MountConfig } from 'cypress/angular';
23+
import chaiColors from 'chai-colors';
24+
import { Type } from '@angular/core';
25+
import { HttpClientTestingModule } from '@angular/common/http/testing';
26+
27+
chai.use(chaiColors);
2328

2429
// Augment the Cypress namespace to include type definitions for
2530
// your custom command.
2631
// Alternatively, can be defined in cypress/support/component.d.ts
2732
// with a <reference path="./component" /> at the top of your spec.
2833
declare global {
34+
// eslint-disable-next-line @typescript-eslint/no-namespace
2935
namespace Cypress {
3036
interface Chainable {
31-
mount: typeof mount
37+
mount: typeof mount;
38+
mountStandalone: typeof mount;
3239
}
3340
}
3441
}
3542

36-
Cypress.Commands.add('mount', mount)
43+
const imports = [HttpClientTestingModule];
44+
45+
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
46+
function customMount<T>(component: string | Type<T>, config?: MountConfig<T>) {
47+
if (!config) {
48+
config = { imports };
49+
} else {
50+
config.imports = [...(config?.imports || []), ...imports];
51+
}
52+
return mount<T>(component, config);
53+
}
54+
55+
Cypress.Commands.add('mount', mount);
56+
Cypress.Commands.add('mountStandalone', customMount);
3757

3858
// Example use:
39-
// cy.mount(MyComponent)
59+
// cy.mount(MyComponent)

cypress/support/e2e.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands'
17+
import './commands';
1818

1919
// Alternatively you can use CommonJS syntax:
20-
// require('./commands')
20+
// require('./commands')

karma.conf.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
// TFS Intergration
5+
// https://isaacmartinezblog.wordpress.com/2018/04/02/angular-code-coverage-in-sonar-qube-and-vsts/
6+
7+
// ChromeHeadless from Puppeteer
8+
// https://github.com/karma-runner/karma-chrome-launcher
9+
10+
// Set Env for ChromeHeadless from puppeteer
11+
process.env.CHROME_BIN = require('puppeteer').executablePath();
12+
module.exports = function (config) {
13+
config.set({
14+
basePath: '',
15+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
16+
specReporter: {
17+
maxLogLines: 5, // limit number of lines logged per test
18+
suppressWarnSummary: true, // do not print warn summary
19+
suppressErrorSummary: false, // do not print error summary
20+
suppressFailed: false, // do not print information about failed tests
21+
suppressPassed: true, // do not print information about passed tests
22+
suppressSkipped: true, // do not print information about skipped tests
23+
showSpecTiming: false // print the time elapsed for each spec
24+
},
25+
plugins: [
26+
require('karma-jasmine'),
27+
require('karma-chrome-launcher'),
28+
require('karma-coverage'),
29+
require('karma-junit-reporter'),
30+
require('@angular-devkit/build-angular/plugins/karma'),
31+
require('puppeteer')
32+
],
33+
client: {
34+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
35+
jasmine: {
36+
random: false
37+
}
38+
},
39+
40+
files: [],
41+
preprocessors: {},
42+
mime: {
43+
'text/x-typescript': ['ts', 'tsx']
44+
},
45+
junitReporter: {
46+
outputDir: '../../coverage', // results will be saved as $outputDir/$browserName.xml
47+
useBrowserName: false, // add browser name to report and classes names
48+
outputFile: 'TEST-loads-ui-report.xml' // if included, results will be saved as $outputDir/$browserName/$outputFile
49+
},
50+
coverageReporter: {
51+
dir: '../../coverage',
52+
subdir: 'loads-ui',
53+
fixWebpackSourcePaths: true,
54+
reporters: [
55+
{ type: 'lcovonly', file: 'lcov.info' },
56+
{ type: 'lcov' }
57+
]
58+
},
59+
reporters: ['junit', 'coverage', 'progress'],
60+
port: 9876,
61+
colors: true,
62+
logLevel: config.LOG_INFO,
63+
autoWatch: true,
64+
browsers: ['Chrome_without_security'],
65+
// you can define custom flags
66+
customLaunchers: {
67+
Chrome_without_security: {
68+
base: 'ChromeHeadless',
69+
flags: [
70+
'--disable-gpu',
71+
'--no-sandbox',
72+
'--disable-translate',
73+
'--disable-extensions',
74+
],
75+
}
76+
},
77+
singleRun: false,
78+
restartOnFileChange: true,
79+
captureTimeout: 2100000,
80+
browserDisconnectTimeout: 210000,
81+
browserDisconnectTolerance: 3,
82+
browserNoActivityTimeout: 2100000,
83+
reportSlowerThan: 100,
84+
browserConsoleLogOptions: { level: 'debug', terminal: false }
85+
});
86+
};

package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-37
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"test": "jest --collectCoverage",
99
"test:update": "jest -u",
1010
"test:uc": "jest --collectCoverage -u",
11-
"test:watch": "jest --watch",
1211
"lint": "ng lint --fix && yarn js-beautify src/**/*.css && yarn js-beautify src/**/*.html",
1312
"cypress:open": "cypress open --config-file cypress/config/local.config.ts",
1413
"cypress:open-dev": "cypress open --config-file cypress/config/dev.config.ts",
@@ -38,7 +37,6 @@
3837
"zone.js": "0.11.8"
3938
},
4039
"devDependencies": {
41-
"@angular-builders/jest": "14.0.1",
4240
"@angular-devkit/build-angular": "14.2.5",
4341
"@angular-eslint/builder": "14.1.2",
4442
"@angular-eslint/eslint-plugin": "14.1.2",
@@ -50,30 +48,35 @@
5048
"@angular/language-service": "14.2.5",
5149
"@bahmutov/cypress-extends": "1.1.0",
5250
"@cypress/code-coverage": "3.10.0",
53-
"@ngneat/spectator": "^11.3.0",
54-
"@types/jest": "^29.2.0",
51+
"@types/jasmine": "^4.3.0",
52+
"@types/jasminewd2": "^2.0.10",
5553
"@types/node": "^12.11.1",
5654
"@typescript-eslint/eslint-plugin": "^5.39.0",
5755
"@typescript-eslint/parser": "^5.39.0",
56+
"chai-colors": "^1.0.1",
5857
"check-code-coverage": "^1.10.0",
5958
"cypress": "^10.10.0",
6059
"eslint": "^8.25.0",
6160
"eslint-config-prettier": "^8.3.0",
6261
"eslint-plugin-cypress": "2.12.1",
6362
"eslint-plugin-import": "^2.26.0",
64-
"eslint-plugin-jest": "^27.1.3",
6563
"eslint-plugin-jsdoc": "^39.3.20",
6664
"eslint-plugin-prefer-arrow": "^1.2.3",
6765
"eslint-plugin-prettier": "^4.2.1",
6866
"husky": "^8.0.1",
69-
"jest": "^29.2.1",
70-
"jest-canvas-mock": "^2.4.0",
71-
"jest-chain": "^1.1.6",
72-
"jest-preset-angular": "^12.2.2",
67+
"jasmine-core": "^4.5.0",
68+
"jasmine-spec-reporter": "^7.0.0",
69+
"karma": "^6.4.1",
70+
"karma-chrome-launcher": "^3.1.1",
71+
"karma-cli": "^2.0.0",
72+
"karma-coverage": "^2.2.0",
73+
"karma-jasmine": "^5.1.0",
74+
"karma-junit-reporter": "^2.0.1",
7375
"js-beautify": "^1.13.13",
7476
"ng-mocks": "^14.2.3",
7577
"ngx-build-plus": "14.0.0",
7678
"prettier": "^2.2.1",
79+
"puppeteer": "^19.2.1",
7780
"start-server-and-test": "^1.12.1",
7881
"stylelint": "^13.13.0",
7982
"stylelint-config-standard": "^22.0.0",
@@ -95,34 +98,6 @@
9598
"not dead",
9699
"not IE 9-11"
97100
],
98-
"jest": {
99-
"preset": "jest-preset-angular",
100-
"coverageDirectory": "coverage",
101-
"collectCoverageFrom": [
102-
"src/app/**/*.ts",
103-
"src/app/*.ts",
104-
"!src/app/**/*.module.ts",
105-
"!src/app/**/*-comparison.ts"
106-
],
107-
"setupFilesAfterEnv": [
108-
"<rootDir>/setup-jest.ts",
109-
"jest-chain"
110-
],
111-
"testPathIgnorePatterns": [
112-
"<rootDir>/node_modules/",
113-
"<rootDir>/dist/",
114-
"<rootDir>/cypress/"
115-
],
116-
"globals": {
117-
"ts-jest": {
118-
"tsconfig": "<rootDir>/tsconfig.spec.json",
119-
"stringifyContentPathRegex": "\\.html$"
120-
}
121-
},
122-
"moduleNameMapper": {
123-
"@core/(.*)": "<rootDir>/src/app/core/$1"
124-
}
125-
},
126101
"nyc": {
127102
"report-dir": "coverage-e2e",
128103
"extension": [

setup-jest.ts

-30
This file was deleted.

src/app/about/about.component.cy.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { AboutComponent } from './about.component';
2-
import { HttpClientTestingModule } from '@angular/common/http/testing';
2+
import { TwainService } from '../twain/twain.service';
3+
import { Observable, of } from 'rxjs';
4+
import { QuoteServiceModel } from '../twain/quote.service.model';
5+
import { Injectable } from '@angular/core';
6+
7+
@Injectable()
8+
class MockTwainService implements QuoteServiceModel {
9+
getQuote(): Observable<string> {
10+
return of('Be Inspired!');
11+
}
12+
}
313

414
describe('About Component', () => {
515
// Mount the component before the start of the test
616
beforeEach(() => {
7-
cy.mount(AboutComponent, {
8-
imports: [HttpClientTestingModule]
17+
cy.mountStandalone(AboutComponent, {
18+
providers: [{ provide: TwainService, useClass: MockTwainService }]
919
});
1020
});
1121

1222
it('Loads with a title and highlight', () => {
1323
cy.get('[data-cy=page-title]')
1424
.should('have.text', 'About')
1525
.should('have.css', 'background-color')
16-
.and('eq', 'rgb(135, 206, 235)');
26+
.and('be.colored', 'skyblue');
27+
});
28+
29+
it('should have an h3 element that reads "Quote of the day:"', () => {
30+
cy.get('h3')
31+
.should('have.text', 'Quote of the day:');
1732
});
33+
1834
});

0 commit comments

Comments
 (0)