-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Spectator + Jest with Jasmine and default Testbed #696
base: master
Are you sure you want to change the base?
Replace Spectator + Jest with Jasmine and default Testbed #696
Conversation
@@ -60,9 +85,9 @@ describe('ProjectPageComponent', () => { | |||
xit('should show section to add new quickstarters when edit-button is clicked', () => { | |||
/* given */ | |||
/* when */ | |||
spectator.click('[data-test-edit-btn]'); | |||
spectator.detectComponentChanges(); | |||
// spectator.click('[data-test-edit-btn]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these lines are commented our, they can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better: the test is commented out (xit()
) 😉
@cschweikert do you have time to review this, too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sry for the long response time 😅 I reviewed only half of it so far, but wanted to bring already some comments to the table.
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['Chrome'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend to use headless Chrome for also beeing able to run this within the build pipelines. The following configuration does the trick:
...
browsers: ['ChromeNoSandboxHeadless'],
customLaunchers: {
ChromeNoSandboxHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
// See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
'--headless',
'--disable-gpu',
// Without a remote debugging port, Google Chrome exits immediately.
'--remote-debugging-port=9222',
'--js-flags="--max_old_space_size=2048"',
],
},
},
...
This is also what the angular quickstarter usually uses.
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test": "ng test", | ||
"test:watch": "ng test --watch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken ng test
is already watching by default. I'd propose to provide something like this:
"test": "ng test --watch=false --progress=false --code-coverage",
"test:watch": "ng test",
BTW: "test"
is similar to the one in the quickstarter (https://github.com/opendevstack/ods-quickstarters/blob/8a236d71902c8fb203fc944bf9d93ee34d16ab03/fe-angular/files/package.json#L8).
@@ -4,6 +4,7 @@ | |||
|
|||
### Added | |||
|
|||
- SPA: Replace Spectator unit test framework by Angular Testbed default ([#539](https://github.com/opendevstack/ods-provisioning-app/issues/539)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it replacing Jest with Jasmine/Karma (Angular default)? Ah, I guess Jest is using @ngneat/spectator
somewhere, right? I would at least mention Jest in the changelog. Also I would mention the Angular update from 12.1.2 to 12.1.4.
"@angular-eslint/template-parser": "^12.3.1", | ||
"@angular/cli": "~12.1.4", | ||
"@angular/compiler-cli": "~12.1.4", | ||
"@angular/language-service": "~12.1.4", | ||
"@ngneat/spectator": "^8.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is @ngneat/spectator
still needed in the devDependencies
?
@@ -37,7 +27,7 @@ describe('ProjectHeaderComponent', () => { | |||
imports: [ | |||
ProjectModule, | |||
LoadingIndicatorModule, | |||
MatIconModule, | |||
MatIconTestingModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I remember it correctly you would need both MatIconModule
and MatIconTestingModule
for mocking the icons.
imports: [CommonModule, HttpClientTestingModule, MatIconModule, MatTooltipModule, MatExpansionModule, MatDialogModule], | ||
declarations: [QuickstarterListComponent], | ||
imports: [CommonModule, HttpClientTestingModule, MatIconTestingModule, MatTooltipModule, MatExpansionModule, MatDialogModule], | ||
declarations: [QuickstarterListComponent, MatIcon], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity: Why is MatIcon
needed here?
@@ -60,9 +85,9 @@ describe('ProjectPageComponent', () => { | |||
xit('should show section to add new quickstarters when edit-button is clicked', () => { | |||
/* given */ | |||
/* when */ | |||
spectator.click('[data-test-edit-btn]'); | |||
spectator.detectComponentChanges(); | |||
// spectator.click('[data-test-edit-btn]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better: the test is commented out (xit()
) 😉
NotificationModule | ||
], | ||
providers: [ | ||
{ provide: API_PROJECT_DETAIL_URL, useValue: '/api/mock' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this block with API_...
in a couple of spec files. Maybe it makes sense to put it somewhere more central. Would it work to have something like a common test module e.g. with all the Mat...
modules and this block in the providers
section? With this it would be sufficient to only add this new testing module in every spec file.
useValue: { | ||
saveItem: jest.fn() | ||
} | ||
useValue: mockStorageService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockStorageService
is used only here. Maybe simply useValue: {saveItem: () => {}}
or useValue: jasmine.createSpy('saveItem')
?
@netzartist @cschweikert what is the status of this PR? Can we get it done soon or should we cancel it? |
@stitakis Once I find enough blocked time to react to the proposed useful code changes ... Beginning of December I'd estimate. Cancelling is no option. |
Agree to close this due to these overall reasons to go into standby with the development of a new frontend for the prov app:
Also, the implemented Angular stack is outdated, there are better / leaner ways nowadays. |
Resolves #539
This is "just" to have a proper foundation again for unit tests (after Spectator and suprisingly Jest as of latest Angular 12.x didn't work as nicely as expected). Fixing existing or adding more tests (preferably with Cypress to gain better E2E test confidence) will be tackled in other issues.