From 4ba5b368a6faebafc692639974ec29c2307f39d6 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 20 Jun 2018 13:36:10 +0300 Subject: [PATCH] Remove jest because it is not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use Testcafé e2e tests for all kinds of frontend testing --- configs/jest.json | 30 -------- configs/jest.preprocessor.js | 25 ------- package-lock.json | 111 ++++++++++++++++++++++++++++++ package.json | 11 +-- tests/jest/App.test.tsx | 16 ----- tests/jest/__mocks__/fileMock.js | 1 - tests/jest/__mocks__/shim.js | 3 - tests/jest/__mocks__/styleMock.js | 1 - tests/testcafe/index.test.ts | 40 +++++++---- 9 files changed, 144 insertions(+), 94 deletions(-) delete mode 100644 configs/jest.json delete mode 100644 configs/jest.preprocessor.js delete mode 100644 tests/jest/App.test.tsx delete mode 100644 tests/jest/__mocks__/fileMock.js delete mode 100644 tests/jest/__mocks__/shim.js delete mode 100644 tests/jest/__mocks__/styleMock.js diff --git a/configs/jest.json b/configs/jest.json deleted file mode 100644 index 5219a71..0000000 --- a/configs/jest.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "rootDir": "..", - "coverageDirectory": "/tests/jest/__coverage__/", - "setupFiles": [ - "/tests/jest/__mocks__/shim.js" - ], - "roots": [ - "/src/", - "/tests/jest/" - ], - "moduleNameMapper": { - "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/tests/jest/__mocks__/fileMock.js", - "\\.(css|scss|less)$": "/tests/jest/__mocks__/styleMock.js" - }, - "moduleFileExtensions": ["ts", "tsx", "js", "jsx"], - "transform": { - "^.+\\.(ts|tsx)$": "/configs/jest.preprocessor.js" - }, - "transformIgnorePatterns": [ - "/node_modules/" - ], - "testRegex": "/tests/jest/.*\\.(ts|tsx)$", - "moduleDirectories": [ - "node_modules" - ], - "globals": { - "DEVELOPMENT": false, - "FAKE_SERVER": false - } -} diff --git a/configs/jest.preprocessor.js b/configs/jest.preprocessor.js deleted file mode 100644 index 6db70df..0000000 --- a/configs/jest.preprocessor.js +++ /dev/null @@ -1,25 +0,0 @@ -const tsc = require('typescript'); -const tsConfig = require('./../tsconfig.json'); - -module.exports = { - process(src, path) { - const isTs = path.endsWith('.ts'); - const isTsx = path.endsWith('.tsx'); - const isTypescriptFile = (isTs || isTsx); - - if ( isTypescriptFile ) { - src = tsc.transpileModule( - src, - { - compilerOptions: tsConfig.compilerOptions, - fileName: path - } - ).outputText; - - // update the path so babel can try and process the output - path = path.substr(0, path.lastIndexOf('.')) + (isTs ? '.js' : '.jsx') || path; - } - - return src; - }, -}; diff --git a/package-lock.json b/package-lock.json index 7d6f728..414398d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8234,6 +8234,111 @@ "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=", "dev": true }, + "husky": { + "version": "1.0.0-rc.9", + "resolved": "https://registry.npmjs.org/husky/-/husky-1.0.0-rc.9.tgz", + "integrity": "sha512-iGGRXcpwl3qGysa73KAtiZWN/YuQVqwgVsPR0UihVasfIsWaAbOfAsswsGmBhKivGtDCdOiLJPTvEZfGJWiCVw==", + "dev": true, + "requires": { + "cosmiconfig": "^5.0.2", + "execa": "^0.9.0", + "find-up": "^2.1.0", + "get-stdin": "^6.0.0", + "is-ci": "^1.1.0", + "pkg-dir": "^2.0.0", + "read-pkg": "^3.0.0", + "run-node": "^1.0.0", + "slash": "^2.0.0" + }, + "dependencies": { + "cosmiconfig": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.0.5.tgz", + "integrity": "sha512-94j37OtvxS5w7qr7Ta6dt67tWdnOxigBVN4VnSxNXFez9o18PGQ0D33SchKP17r9LAcWVTYV72G6vDayAUBFIg==", + "dev": true, + "requires": { + "is-directory": "^0.3.1", + "js-yaml": "^3.9.0", + "parse-json": "^4.0.0" + } + }, + "execa": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.9.0.tgz", + "integrity": "sha512-BbUMBiX4hqiHZUA5+JujIjNb6TyAlp2D5KLheMjMluwOuzcnylDL4AxZYLLn1n2AGB49eSWwyKvvEQoRpnAtmA==", + "dev": true, + "requires": { + "cross-spawn": "^5.0.1", + "get-stream": "^3.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" + } + }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, + "load-json-file": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", + "integrity": "sha1-L19Fq5HjMhYjT9U62rZo607AmTs=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^4.0.0", + "pify": "^3.0.0", + "strip-bom": "^3.0.0" + } + }, + "parse-json": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "dev": true, + "requires": { + "error-ex": "^1.3.1", + "json-parse-better-errors": "^1.0.1" + } + }, + "path-type": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz", + "integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==", + "dev": true, + "requires": { + "pify": "^3.0.0" + } + }, + "read-pkg": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", + "integrity": "sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=", + "dev": true, + "requires": { + "load-json-file": "^4.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^3.0.0" + } + }, + "slash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + } + } + }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", @@ -16426,6 +16531,12 @@ "is-promise": "^2.1.0" } }, + "run-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/run-node/-/run-node-1.0.0.tgz", + "integrity": "sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A==", + "dev": true + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", diff --git a/package.json b/package.json index 14815b9..15836f4 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,19 @@ "lint:sass": "stylelint ./src/**/**/*.scss ./src/**/*.scss ./src/*.scss", "start": "npm run start-dev", "start-dev": "webpack-dev-server --config=configs/webpack/dev.js", - "test": "npm-run-all test:unit test:e2e", "serve": "node express.js", "start-prod": "npm run build && npm run serve", - "test:unit": "jest --watch --coverage --config=configs/jest.json", + "test": "npm-run-all lint test:e2e", "test:e2e": "npm-run-all -s build -p -r serve test:e2e:run", "test:e2e:run": "testcafe -S -s 'tests/testcafe/screenshots' --app-init-delay 2000 chrome tests/testcafe", "plop": "plop" }, + "husky": { + "hooks": { + "pre-commit": "npm run test" + } + }, "devDependencies": { - "@types/jest": "^23.0.0", "@types/node": "^10.3.1", "@types/react": "^16.3.16", "@types/react-dom": "^16.0.6", @@ -46,8 +49,8 @@ "express": "^4.16.3", "file-loader": "^1.1.11", "html-webpack-plugin": "^3.2.0", + "husky": "^1.0.0-rc.9", "image-webpack-loader": "^4.3.0", - "jest": "^23.1.0", "node-sass": "^4.9.0", "npm-run-all": "^4.1.3", "plop": "^2.0.0", diff --git a/tests/jest/App.test.tsx b/tests/jest/App.test.tsx deleted file mode 100644 index 352f0e2..0000000 --- a/tests/jest/App.test.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import * as React from 'react'; -import * as ReactDOM from 'react-dom'; -import * as TestUtils from 'react-dom/test-utils'; -import App from '../../src/components/App'; - -it('App is rendered', () => { - // Render App in the document - const appElement: any = TestUtils.renderIntoDocument( - - ); - - const appNode = ReactDOM.findDOMNode(appElement); - - // Verify text content - expect(appNode.textContent).toEqual('Aalto-yliopiston sähköinsinöörikilta!Sähköä, viinaa, naisia.'); -}); diff --git a/tests/jest/__mocks__/fileMock.js b/tests/jest/__mocks__/fileMock.js deleted file mode 100644 index 86059f3..0000000 --- a/tests/jest/__mocks__/fileMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'test-file-stub'; diff --git a/tests/jest/__mocks__/shim.js b/tests/jest/__mocks__/shim.js deleted file mode 100644 index 7947f08..0000000 --- a/tests/jest/__mocks__/shim.js +++ /dev/null @@ -1,3 +0,0 @@ -global.requestAnimationFrame = (callback) => { - setTimeout(callback, 0); -}; diff --git a/tests/jest/__mocks__/styleMock.js b/tests/jest/__mocks__/styleMock.js deleted file mode 100644 index f053ebf..0000000 --- a/tests/jest/__mocks__/styleMock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; diff --git a/tests/testcafe/index.test.ts b/tests/testcafe/index.test.ts index 70553c6..920e673 100644 --- a/tests/testcafe/index.test.ts +++ b/tests/testcafe/index.test.ts @@ -3,23 +3,35 @@ * This file is used by TestCafé to run end-to-end tests with chrome against the site. * Tests are grouped into fixtures and fixtures into files. */ -import { Selector } from 'testcafe'; +import { Selector } from "testcafe"; -fixture`Page renders correctly`.page('http://localhost:3000'); +fixture`Page renders correctly`.page("http://localhost:3000"); -test('Paragraph exists and is visible', async t => { - /** - * Test if there is a paragraph on the page. - */ - const p = Selector('p'); - await t.expect(await p.exists && await p.visible); +test("Paragraph exists and is visible", async t => { + /** + * Test if there is a paragraph on the page. + */ + const p = Selector("p"); + await t.expect(p.exists).ok(); }); -test('Header contains text "Aalto-yliopiston sähköinsinöörikilta!"', async t => { - /** - * Test if the header contains the text. - */ - const header = Selector('h1'); +test("Header contains text \"Aalto-yliopiston sähköinsinöörikilta!\"", async t => { + /** + * Test if the header contains the text. + */ + const header = Selector("h1"); const text = await header.textContent; - await t.expect(text.includes('Aalto-yliopiston sähköinsinöörikilta!')); + await t.expect(text).contains("Aalto-yliopiston sähköinsinöörikilta!"); +}); + +fixture`Increment button`.page("http://localhost:3000"); + +test("Increment button functions correctly", async t => { + /** + * Test if the increment button works and increments the number inside the button + */ + const button = Selector("button"); + await t.expect(button.textContent).contains("0"); + await t.click(button); + await t.expect(button.textContent).contains("1"); }); \ No newline at end of file