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

Improve testing infrastructure #184

Merged
merged 43 commits into from
Jun 24, 2024

Conversation

dchege711
Copy link
Owner

  • Use supertest to bring up an app instance and run E2E tests on it.
  • Clean up the setup and teardown logic of server-side tests.
  • Set up web-test-runner for client-side testing.

Contributes to #183

dchege711 added 30 commits June 16, 2024 17:49
That way, tests can exercise various code paths without
interference.
Intended for use in testing client-side web components
Otherwise, `npm run test:client` errors out looking for the server's config.
added 186 packages, changed 1 package, and audited 1102 packages in 11s
added 9 packages, and audited 1111 packages in 4s
Needed for client-side testing that uses ES modules.
The logs are working as expected, erroring out in the TS file:

```log
src/models/core/graph.test.ts:

 ❌ Test Graph
 > should have undirected edges
      AssertionError: expected 2 to equal 3
      + expected - actual

      -2
      +3

      at n.<anonymous> (src/models/core/graph.test.ts:11:42)
```

This reverts commit 2021655.
Generated via:

```zsh
$ git revert 0835a07 --no-commit
$ npm install --save-dev @esm-bundle/chai
```

Previously, installing `chai@npm:@esm-bundle/chai` made the server-side
tests also use the ES module version, which led to ts-mocha breaking:

```log
TypeError: Unknown file extension ".ts"
```
…e/chai

@open-wc/testing exposes chai as an ESM, and has useful plugins that are
pre-configured:

* @open-wc/semantic-dom-diff for dom tree / snapshot testing
* @open-wc/chai-a11y-axe for a11y testing
* chai-dom for dom testing

No need to install @esm-bundle/chai separately.

[1]: https://open-wc.org/docs/testing/testing-package/
`npm test src/components/search-bar/search-bar.test.ts` fails with:

```log
src/components/search-bar/search-bar.test.ts:

 🚧 Browser logs:
      Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.
      An error was thrown in a Promise outside a test. Did you forget to await a function or assertion?
      TRPCClientError: Unexpected token 'N', "Not Found" is not valid JSON
        at TRPCClientError.from (../../node_modules/@trpc/client/dist/TRPCClientError.mjs:37:16)
        at ../../node_modules/@trpc/client/dist/links/internals/httpUtils.mjs:110:36

 🚧 404 network requests:
    - trpc/searchPublicCards?batch=1&input=%7B%220%22%3A%7B%22limit%22%3Anull%2C%22queryString%22%3A%22%22%7D%7D

 ❌ search-bar > should fetch initial results on load
      Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
        at createTimeoutError (../../node_modules/@web/test-runner-mocha/dist/autorun.js:1:191473)
        at ds._timeoutError (../../node_modules/@web/test-runner-mocha/dist/autorun.js:1:195706)
        at ../../node_modules/@web/test-runner-mocha/dist/autorun.js:1:193787
```

... because the test is trying to fetch data from the server.
The requests still 404 out. Will revert shortly.
Copy link

render bot commented Jun 24, 2024

@dchege711 dchege711 merged commit b9a4a17 into main Jun 24, 2024
4 checks passed
@dchege711 dchege711 deleted the user/dchege711/testing/improve-testing-infra branch June 24, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant