Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
feat: add cypress + jest
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Feb 11, 2022
1 parent f4facf3 commit b9659cb
Show file tree
Hide file tree
Showing 12 changed files with 3,358 additions and 28 deletions.
3 changes: 3 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
10 changes: 10 additions & 0 deletions cypress/integration/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
// Disable ESLint to prevent failing linting inside the Next.js repo.
// If you're using ESLint on your project, we recommend installing the ESLint Cypress plugin instead:
// https://github.com/cypress-io/eslint-plugin-cypress

describe("Basic", () => {
it("should render the main page", () => {
cy.visit("http://localhost:3000/");
});
});
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
Binary file added cypress/videos/app.spec.js.mp4
Binary file not shown.
32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// jest.config.js
const nextJest = require("next/jest");

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});

// Add any custom config to be passed to Jest
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ["node_modules", "<rootDir>/"],
testEnvironment: "jest-environment-jsdom",
testPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/.next/",
"<rootDir>/cypress/",
],
moduleNameMapper: {
"@components": "<rootDir>/src/components",
"@config": "<rootDir>/src/config",
"@utils": "<rootDir>/src/utils",
"@hooks": "<rootDir>/src/hooks",
"@modules": "<rootDir>/src/modules",
"@lib": "<rootDir>/src/lib",
},
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
"start": "next start",
"lint": "next lint",
"export": "next export",
"build:export": "yarn build && yarn export"
"build:export": "yarn build && yarn export",
"e2e": "cypress open",
"e2e:headless": "cypress run",
"test": "jest",
"test:watch": "jest --watch",
"test:e2e": "start-server-and-test dev http://localhost:3000 e2e",
"test:e2e:headless": "start-server-and-test dev http://localhost:3000 e2e:headless"
},
"dependencies": {
"@dataesr/react-dsfr": "^1.0.2",
Expand All @@ -18,11 +24,16 @@
"react-dom": "17.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@types/node": "17.0.13",
"@types/react": "17.0.38",
"cypress": "^9.4.1",
"eslint": "8.7.0",
"eslint-config-next": "12.0.9",
"jest": "^27.5.1",
"next-sitemap": "^2.1.14",
"start-server-and-test": "^1.14.0",
"typescript": "4.5.5"
},
"version": "1.2.1"
Expand Down
2 changes: 1 addition & 1 deletion public/sitemap-0.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://template.fabrique.social.gouv.fr</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2022-02-11T12:02:37.947Z</lastmod></url>
<url><loc>https://template.fabrique.social.gouv.fr</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2022-02-11T15:07:07.677Z</lastmod></url>
</urlset>
13 changes: 13 additions & 0 deletions src/components/__tests__/layout.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Layout } from "@components";
import { render, screen } from "@testing-library/react";

describe("Layout", () => {
it("renders copyright", async () => {
render(
<Layout>
<div />
</Layout>
);
expect(screen.getAllByText("© République Française 2022")).toBeDefined();
});
});
Loading

0 comments on commit b9659cb

Please sign in to comment.