Repository navigation
Fix the karma suite and run it in CI - #90
Open
matthewberry wants to merge 3 commits into
Open
matthewberry wants to merge 3 commits into
matthewberry wants to merge 3 commits into
Conversation
The suite hadn't compiled on main, and once it did, 26 of 41 specs failed. Nothing ran it in CI, so it drifted. - Fix three compile errors: two directive specs called constructors that now take services, and the ECNumber spec used the component's old class name. - Add src/app/testing/test-providers.ts with what main.ts provides at bootstrap (HttpClient, router, animations) plus an EnvironmentService stub, and use it in the component specs that need it. - Set required inputs in four specs, and import FontMatchComponent instead of declaring it, since it is standalone. - Add a Test workflow that runs ng test on pushes to main/develop and on PRs.
npm ci failed with a 401 on @moleculemaker/dev-tool, because the Test workflow never passed GITHUB_TOKEN to npm the way docker.yml does. Set the registry and token through setup-node, and limit the token to contents: read and packages: read, which also answers the CodeQL missing-permissions alert.
testProviders already provides the router through provideRouter([]), so the spec was setting it up twice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On
main, the karma suite fails to compile, song testnever runs a single spec. Once the compile errors are fixed, 26 of 41 specs fail. Nothing in CI runs the tests, which is how it drifted. This PR makes all 41 pass and adds a workflow that runs them.Changes
molecule-name-validatorandsmiles-validatorspecs called the directive constructors with no arguments, but they now inject services. The specs now pass stubs.entity-ecnumber.component.spec.tsimportedEntityEcnumberComponent, but the class is nowEntityECNumberComponent.No provider for HttpClient/ActivatedRoute. Once those were added, the next errors wereEnvironmentServiceand animations. The newsrc/app/testing/test-providers.tsholds whatmain.tsprovides at bootstrap:provideHttpClient(),provideHttpClientTesting(),provideRouter([])andprovideNoopAnimations(). It also stubsEnvironmentService, becausemain.tsloads its config in anAPP_INITIALIZERthat TestBed never runs, and every service that injects it callsgetEnvConfig()in its constructor. Each failing spec now hasproviders: testProviders.ExternalLinkComponent,FilterComponent,ReactionSchemeComponentandMolecule3dComponentread their inputs during the first change detection. The specs now set them.ReactionSchemeandMolecule3dusesetInputso thatngOnChangesfires.FontMatchComponentis standalone, so its spec now imports it instead of declaring it..github/workflows/test.ymlrunsnpm ciandng test --watch=false --browsers=ChromeHeadlesson Node 22, matching the Dockerfile. It triggers the same way asdocker.yml: pushes tomain/developand every PR.Testing
ng test --watch=false --browsers=ChromeHeadless: 41 of 41 passed.mainwith only the compile errors fixed: 15 passed, 26 failed.The run still prints some noise that doesn't fail it:
baseZIndexdeprecation warnings.Injector has already been destroyederrors from async work that finishes after a spec tears down. I didn't track down which spec causes them.Conflicts
This PR and #89 both edit the provider setup in
about-page.component.spec.ts. Whichever merges second needs a small rebase. If #89 goes second, its spec can useproviders: [...testProviders, { provide: OEDService, useValue: oedService }].Most of these specs still only check that the component can be created. This PR makes them run; it doesn't add coverage.