codeforjapan / hackdays

Next version of Social Hackday website.
hackdays-c4j.vercel.app
6 stars 0 forks source link

[Story] TDD environment #21

Closed halsk closed 2 years ago

halsk commented 2 years ago

Goal:

As a developer, I want to develop with a test-driven process so that I can keep code quality high.

Tasks:

  1. Add test environment
  2. Write test code!
  3. Write documents about the test

Acceptance Criteria:

halsk commented 2 years ago

This is the official nextjs page for testing https://nextjs.org/docs/testing

halsk commented 2 years ago

@MaySoMusician

E2E test worked but the unit test didn't work. Here is the log.

% yarn test:ci
yarn run v1.22.17
$ jest --ci
"next/jest" is currently experimental. https://nextjs.org/docs/messages/experimental-jest-transformer
 FAIL  cypress/integration/app.spec.js
  ● example test › shows the top page

    ReferenceError: cy is not defined

      3 | describe('example test', () => {
      4 |   it('shows the top page', () => {
    > 5 |     cy.visit('http://localhost:3000/');
        |         ^
      6 |     cy.get('h1').contains('Find wonderful projects');
      7 |   });
      8 | });

      at Object.<anonymous> (cypress/integration/app.spec.js:5:9)

 PASS  __test__/atoms/button/PrimaryButton.test.tsx

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        1.56 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
MaySoMusician commented 2 years ago

@halsk It seems that Jest wrongly runs the E2E tests. yarn test:ci should not touch the tests in cypress/. I'll do deeper investigation.

MaySoMusician commented 2 years ago

I've found the way to tell Jest to ignore Cypress tests.