diff --git a/README.md b/README.md index c0b7d5e..0fd8baa 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ To run all tests, including all linting tests: npm test ``` -All test files live beside the respective component. Testing setup, fixtures, and mocks can be found in `./jest.config.js` and `./jest` folder. +Most test files live beside the respective component. Testing setup, fixtures, and mocks can be found in the `./tests/` folder. ### 🎈 Add a new project diff --git a/jest/jest-preprocess.js b/jest/jest-preprocess.js deleted file mode 100644 index 95114e5..0000000 --- a/jest/jest-preprocess.js +++ /dev/null @@ -1,5 +0,0 @@ -const babelOptions = { - presets: ['babel-preset-gatsby'] -} - -module.exports = require('babel-jest').createTransformer(babelOptions) diff --git a/package.json b/package.json index 549c30e..27379f9 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "lint:css": "stylelint ./src/**/*.{css,scss}", "lint": "npm run lint:js && npm run lint:css", "format": "prettier --write 'src/**/*.{js,jsx,css,scss}'", - "test": "npm run lint && jest --coverage --silent", - "test:watch": "npm run lint && jest --coverage --watch", + "test": "npm run lint && jest --coverage --silent -c tests/jest.config.js", + "test:watch": "npm run lint && jest --coverage --watch -c tests/jest.config.js", "deploy:s3": "./scripts/deploy-s3.sh", "new": "babel-node ./scripts/new.js" }, diff --git a/src/components/atoms/Vcard.test.jsx b/src/components/atoms/Vcard.test.jsx index ee224b9..e775234 100644 --- a/src/components/atoms/Vcard.test.jsx +++ b/src/components/atoms/Vcard.test.jsx @@ -1,8 +1,8 @@ import React from 'react' import { render, fireEvent, waitForElement } from '@testing-library/react' import Vcard, { constructVcard, toDataURL, init } from './Vcard' -import meta from '../../../jest/__fixtures__/meta.json' -import resume from '../../../jest/__fixtures__/resume.json' +import meta from '../../../tests/__fixtures__/meta.json' +import resume from '../../../tests/__fixtures__/resume.json' const metaMock = { ...meta.metaYaml, diff --git a/src/components/molecules/LogoUnit.test.jsx b/src/components/molecules/LogoUnit.test.jsx index 1058e47..8a9f565 100644 --- a/src/components/molecules/LogoUnit.test.jsx +++ b/src/components/molecules/LogoUnit.test.jsx @@ -1,7 +1,7 @@ import React from 'react' import { render } from '@testing-library/react' import LogoUnit from './LogoUnit' -import data from '../../../jest/__fixtures__/meta.json' +import data from '../../../tests/__fixtures__/meta.json' describe('LogoUnit', () => { it('renders correctly from data file values', () => { diff --git a/src/components/molecules/Repository.test.jsx b/src/components/molecules/Repository.test.jsx index f10103d..1990337 100644 --- a/src/components/molecules/Repository.test.jsx +++ b/src/components/molecules/Repository.test.jsx @@ -1,7 +1,7 @@ import React from 'react' import { render } from '@testing-library/react' import Repository from './Repository' -import repos from '../../../jest/__fixtures__/repos.json' +import repos from '../../../tests/__fixtures__/repos.json' describe('Repository', () => { it('renders correctly', () => { diff --git a/src/components/organisms/Repositories.test.jsx b/src/components/organisms/Repositories.test.jsx index fb1ae48..76cc56f 100644 --- a/src/components/organisms/Repositories.test.jsx +++ b/src/components/organisms/Repositories.test.jsx @@ -1,7 +1,7 @@ import React from 'react' import { render } from '@testing-library/react' import Repositories from './Repositories' -import repos from '../../../jest/__fixtures__/repos.json' +import repos from '../../../tests/__fixtures__/repos.json' describe('Repositories', () => { it('renders correctly', () => { diff --git a/src/pages/__tests__/index.test.jsx b/tests/Home.test.jsx similarity index 73% rename from src/pages/__tests__/index.test.jsx rename to tests/Home.test.jsx index bc1db85..0f886ca 100644 --- a/src/pages/__tests__/index.test.jsx +++ b/tests/Home.test.jsx @@ -1,8 +1,8 @@ import React from 'react' import { render } from '@testing-library/react' -import Home from '../index' -import projects from '../../../jest/__fixtures__/projects.json' -import projectImageFiles from '../../../jest/__fixtures__/projectImageFiles.json' +import Home from '../src/pages/index' +import projects from './__fixtures__/projects.json' +import projectImageFiles from './__fixtures__/projectImageFiles.json' describe('Home', () => { const data = { diff --git a/src/pages/__tests__/Project.test.jsx b/tests/Project.test.jsx similarity index 81% rename from src/pages/__tests__/Project.test.jsx rename to tests/Project.test.jsx index 747f450..2b10469 100644 --- a/src/pages/__tests__/Project.test.jsx +++ b/tests/Project.test.jsx @@ -1,8 +1,8 @@ import React from 'react' import { render } from '@testing-library/react' import { createHistory, createMemorySource } from '@reach/router' -import Project from '../{ProjectsYaml.slug}' -import project from '../../../jest/__fixtures__/project.json' +import Project from '../src/pages/{ProjectsYaml.slug}' +import project from './__fixtures__/project.json' describe('Project', () => { const history = createHistory(createMemorySource('/oceanprotocol')) diff --git a/jest/__fixtures__/meta.json b/tests/__fixtures__/meta.json similarity index 100% rename from jest/__fixtures__/meta.json rename to tests/__fixtures__/meta.json diff --git a/jest/__fixtures__/project.json b/tests/__fixtures__/project.json similarity index 100% rename from jest/__fixtures__/project.json rename to tests/__fixtures__/project.json diff --git a/jest/__fixtures__/projectImageFiles.json b/tests/__fixtures__/projectImageFiles.json similarity index 100% rename from jest/__fixtures__/projectImageFiles.json rename to tests/__fixtures__/projectImageFiles.json diff --git a/jest/__fixtures__/projects.json b/tests/__fixtures__/projects.json similarity index 100% rename from jest/__fixtures__/projects.json rename to tests/__fixtures__/projects.json diff --git a/jest/__fixtures__/repos.json b/tests/__fixtures__/repos.json similarity index 100% rename from jest/__fixtures__/repos.json rename to tests/__fixtures__/repos.json diff --git a/jest/__fixtures__/resume.json b/tests/__fixtures__/resume.json similarity index 100% rename from jest/__fixtures__/resume.json rename to tests/__fixtures__/resume.json diff --git a/jest/__mocks__/file-mock.js b/tests/__mocks__/file-mock.js similarity index 100% rename from jest/__mocks__/file-mock.js rename to tests/__mocks__/file-mock.js diff --git a/jest/__mocks__/gatsby.js b/tests/__mocks__/gatsby.js similarity index 100% rename from jest/__mocks__/gatsby.js rename to tests/__mocks__/gatsby.js diff --git a/jest/__mocks__/svgr-mock.js b/tests/__mocks__/svgr-mock.js similarity index 100% rename from jest/__mocks__/svgr-mock.js rename to tests/__mocks__/svgr-mock.js diff --git a/jest.config.js b/tests/jest.config.js similarity index 59% rename from jest.config.js rename to tests/jest.config.js index 260f999..40f340d 100644 --- a/jest.config.js +++ b/tests/jest.config.js @@ -1,12 +1,10 @@ module.exports = { - transform: { - '^.+\\.jsx?$': '/jest/jest-preprocess.js' - }, + rootDir: '../', moduleNameMapper: { '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy', '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/jest/__mocks__/file-mock.js', - '\\.svg': '/jest/__mocks__/svgr-mock.js' + '/tests/__mocks__/file-mock.js', + '\\.svg': '/tests/__mocks__/svgr-mock.js' }, testPathIgnorePatterns: [ 'node_modules', @@ -18,6 +16,6 @@ module.exports = { globals: { __PATH_PREFIX__: '' }, - setupFiles: ['/jest/loadershim.js'], - setupFilesAfterEnv: ['/jest/setup-test-env.js'] + setupFiles: ['/tests/loadershim.js'], + setupFilesAfterEnv: ['/tests/setup-test-env.js'] } diff --git a/jest/loadershim.js b/tests/loadershim.js similarity index 100% rename from jest/loadershim.js rename to tests/loadershim.js diff --git a/src/pages/__tests__/resume.test.jsx b/tests/resume.test.jsx similarity index 86% rename from src/pages/__tests__/resume.test.jsx rename to tests/resume.test.jsx index 85c0b88..6a2cd8d 100644 --- a/src/pages/__tests__/resume.test.jsx +++ b/tests/resume.test.jsx @@ -1,6 +1,6 @@ import React from 'react' import { render } from '@testing-library/react' -import Resume from '../resume' +import Resume from '../src/pages/resume' describe('Resume', () => { it('renders correctly from data file values', () => { diff --git a/jest/setup-test-env.js b/tests/setup-test-env.js similarity index 100% rename from jest/setup-test-env.js rename to tests/setup-test-env.js