Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

netzartist
Copy link
Contributor

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.

@netzartist netzartist added the frontend-spa Issues belonging to SPA Angular frontend label Aug 3, 2021
@netzartist netzartist self-assigned this Aug 3, 2021
@@ -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]');
Copy link
Member

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

Copy link
Member

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()) 😉

@netzartist
Copy link
Contributor Author

@cschweikert do you have time to review this, too?

Copy link
Member

@cschweikert cschweikert left a 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'],
Copy link
Member

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",
Copy link
Member

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))
Copy link
Member

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",
Copy link
Member

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,
Copy link
Member

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],
Copy link
Member

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]');
Copy link
Member

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' },
Copy link
Member

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
Copy link
Member

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')?

@stitakis
Copy link
Member

@netzartist @cschweikert what is the status of this PR? Can we get it done soon or should we cancel it?

@netzartist
Copy link
Contributor Author

netzartist commented Nov 12, 2021

@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.

@netzartist
Copy link
Contributor Author

Agree to close this due to these overall reasons to go into standby with the development of a new frontend for the prov app:

  • it's unclear how provisioning should work in the era of ODS pipelines
  • there are other ideas which kind of UI might be more useful to implement
  • no use case to qualify for a strong focus (and a allocation of dev time) on implementing an UI

Also, the implemented Angular stack is outdated, there are better / leaner ways nowadays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend-spa Issues belonging to SPA Angular frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Spectator unit test framework by Angular Testbed default
3 participants