From 9d7be476ad3bdae05efa1c86e6002cb8de001154 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Wed, 1 May 2019 21:02:46 +0200 Subject: [PATCH] chore: relocate unit test (#39) add new json snapshot serializer --- jest.config.js | 3 ++- package.json | 1 + test/unit/__helper.js | 5 ----- test/unit/{webui => }/app.spec.js | 10 +++++----- test/unit/{webui => }/components/__mocks__/api.js | 0 test/unit/{webui => }/components/__mocks__/token.js | 0 .../__snapshots__/copyToClipBoard.spec.js.snap | 0 .../components/__snapshots__/footer.spec.js.snap | 0 .../components/__snapshots__/header.spec.js.snap | 0 .../components/__snapshots__/help.spec.js.snap | 0 .../components/__snapshots__/login.spec.js.snap | 0 .../components/__snapshots__/noitems.spec.js.snap | 0 .../components/__snapshots__/notfound.spec.js.snap | 2 +- .../components/__snapshots__/package.spec.js.snap | 0 .../components/__snapshots__/packagelist.spec.js.snap | 0 .../components/__snapshots__/readme.spec.js.snap | 0 .../components/__snapshots__/search.spec.js.snap | 0 .../{webui => }/components/copyToClipBoard.spec.js | 4 ++-- test/unit/{webui => }/components/footer.spec.js | 4 ++-- test/unit/{webui => }/components/header.spec.js | 2 +- test/unit/{webui => }/components/help.spec.js | 2 +- test/unit/{webui => }/components/login.spec.js | 2 +- test/unit/{webui => }/components/noitems.spec.js | 2 +- test/unit/{webui => }/components/notfound.spec.js | 2 +- test/unit/{webui => }/components/package.spec.js | 6 +++--- test/unit/{webui => }/components/packagelist.spec.js | 4 ++-- test/unit/{webui => }/components/readme.spec.js | 2 +- test/unit/{webui => }/components/search.spec.js | 8 ++++---- test/unit/{webui => }/components/store/login.js | 2 +- test/unit/{webui => }/components/store/logo.js | 0 test/unit/{webui => }/components/store/package.js | 0 test/unit/{webui => }/components/store/packageMeta.js | 0 test/unit/{webui => }/utils/login.spec.js | 2 +- test/unit/{webui => }/utils/package.spec.js | 2 +- yarn.lock | 7 +++++++ 35 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 test/unit/__helper.js rename test/unit/{webui => }/app.spec.js (92%) rename test/unit/{webui => }/components/__mocks__/api.js (100%) rename test/unit/{webui => }/components/__mocks__/token.js (100%) rename test/unit/{webui => }/components/__snapshots__/copyToClipBoard.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/footer.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/header.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/help.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/login.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/noitems.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/notfound.spec.js.snap (61%) rename test/unit/{webui => }/components/__snapshots__/package.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/packagelist.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/readme.spec.js.snap (100%) rename test/unit/{webui => }/components/__snapshots__/search.spec.js.snap (100%) rename test/unit/{webui => }/components/copyToClipBoard.spec.js (85%) rename test/unit/{webui => }/components/footer.spec.js (79%) rename test/unit/{webui => }/components/header.spec.js (97%) rename test/unit/{webui => }/components/help.spec.js (81%) rename test/unit/{webui => }/components/login.spec.js (98%) rename test/unit/{webui => }/components/noitems.spec.js (88%) rename test/unit/{webui => }/components/notfound.spec.js (87%) rename test/unit/{webui => }/components/package.spec.js (92%) rename test/unit/{webui => }/components/packagelist.spec.js (91%) rename test/unit/{webui => }/components/readme.spec.js (90%) rename test/unit/{webui => }/components/search.spec.js (96%) rename test/unit/{webui => }/components/store/login.js (88%) rename test/unit/{webui => }/components/store/logo.js (100%) rename test/unit/{webui => }/components/store/package.js (100%) rename test/unit/{webui => }/components/store/packageMeta.js (100%) rename test/unit/{webui => }/utils/login.spec.js (97%) rename test/unit/{webui => }/utils/package.spec.js (98%) diff --git a/jest.config.js b/jest.config.js index 15441d4..f867985 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,7 @@ module.exports = { collectCoverage: true, testEnvironment: 'jest-environment-jsdom-global', testURL: 'http://localhost', - testRegex: '(test/unit/webui/.*\\.spec)\\.js', + testRegex: '(test/unit/.*\\.spec)\\.js', setupFiles: [ './test/unit/setup.js' ], @@ -35,6 +35,7 @@ module.exports = { '/build', ], snapshotSerializers: [ + 'enzyme-to-json/serializer', "jest-emotion" ], coveragePathIgnorePatterns: [ diff --git a/package.json b/package.json index fb9250e..381ec8d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "emotion": "9.2.12", "enzyme": "3.9.0", "enzyme-adapter-react-16": "1.10.0", + "enzyme-to-json": "3.3.5", "eslint": "5.14.1", "eslint-config-google": "0.12.0", "eslint-config-prettier": "4.1.0", diff --git a/test/unit/__helper.js b/test/unit/__helper.js deleted file mode 100644 index 95b90b8..0000000 --- a/test/unit/__helper.js +++ /dev/null @@ -1,5 +0,0 @@ -import path from 'path'; - -export const parseConfigurationFile = (name) => { - return path.join(__dirname, `./partials/config/yaml/${name}.yaml`); -}; diff --git a/test/unit/webui/app.spec.js b/test/unit/app.spec.js similarity index 92% rename from test/unit/webui/app.spec.js rename to test/unit/app.spec.js index e4f75bf..0cd9f13 100644 --- a/test/unit/webui/app.spec.js +++ b/test/unit/app.spec.js @@ -1,11 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; -import storage from '../../../src/webui/utils/storage'; -import App from '../../../src/webui/app'; +import storage from '../../src/webui/utils/storage'; +import App from '../../src/webui/app'; import { generateTokenWithTimeRange } from './components/__mocks__/token'; -jest.mock('../../../src/webui/utils/storage', () => { +jest.mock('../../src/webui/utils/storage', () => { class LocalStorageMock { constructor() { this.store = {}; @@ -26,7 +26,7 @@ jest.mock('../../../src/webui/utils/storage', () => { return new LocalStorageMock(); }); -jest.mock('../../../src/webui/utils/api', () => ({ +jest.mock('../../src/webui/utils/api', () => ({ request: require('./components/__mocks__/api').default.request })); @@ -36,7 +36,7 @@ describe('App', () => { beforeEach(() => { wrapper = mount(); }); - + test('toggleLoginModal: should toggle the value in state', () => { const { handleToggleLoginModal } = wrapper.instance(); expect(wrapper.state().showLoginModal).toBeFalsy(); diff --git a/test/unit/webui/components/__mocks__/api.js b/test/unit/components/__mocks__/api.js similarity index 100% rename from test/unit/webui/components/__mocks__/api.js rename to test/unit/components/__mocks__/api.js diff --git a/test/unit/webui/components/__mocks__/token.js b/test/unit/components/__mocks__/token.js similarity index 100% rename from test/unit/webui/components/__mocks__/token.js rename to test/unit/components/__mocks__/token.js diff --git a/test/unit/webui/components/__snapshots__/copyToClipBoard.spec.js.snap b/test/unit/components/__snapshots__/copyToClipBoard.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/copyToClipBoard.spec.js.snap rename to test/unit/components/__snapshots__/copyToClipBoard.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/footer.spec.js.snap b/test/unit/components/__snapshots__/footer.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/footer.spec.js.snap rename to test/unit/components/__snapshots__/footer.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/header.spec.js.snap b/test/unit/components/__snapshots__/header.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/header.spec.js.snap rename to test/unit/components/__snapshots__/header.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/help.spec.js.snap b/test/unit/components/__snapshots__/help.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/help.spec.js.snap rename to test/unit/components/__snapshots__/help.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/login.spec.js.snap b/test/unit/components/__snapshots__/login.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/login.spec.js.snap rename to test/unit/components/__snapshots__/login.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/noitems.spec.js.snap b/test/unit/components/__snapshots__/noitems.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/noitems.spec.js.snap rename to test/unit/components/__snapshots__/noitems.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/notfound.spec.js.snap b/test/unit/components/__snapshots__/notfound.spec.js.snap similarity index 61% rename from test/unit/webui/components/__snapshots__/notfound.spec.js.snap rename to test/unit/components/__snapshots__/notfound.spec.js.snap index 86cafe9..25ca089 100644 --- a/test/unit/webui/components/__snapshots__/notfound.spec.js.snap +++ b/test/unit/components/__snapshots__/notfound.spec.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component in default state 1`] = `ShallowWrapper {}`; +exports[` component should load the component in default state 1`] = ``; diff --git a/test/unit/webui/components/__snapshots__/package.spec.js.snap b/test/unit/components/__snapshots__/package.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/package.spec.js.snap rename to test/unit/components/__snapshots__/package.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap b/test/unit/components/__snapshots__/packagelist.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/packagelist.spec.js.snap rename to test/unit/components/__snapshots__/packagelist.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/readme.spec.js.snap b/test/unit/components/__snapshots__/readme.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/readme.spec.js.snap rename to test/unit/components/__snapshots__/readme.spec.js.snap diff --git a/test/unit/webui/components/__snapshots__/search.spec.js.snap b/test/unit/components/__snapshots__/search.spec.js.snap similarity index 100% rename from test/unit/webui/components/__snapshots__/search.spec.js.snap rename to test/unit/components/__snapshots__/search.spec.js.snap diff --git a/test/unit/webui/components/copyToClipBoard.spec.js b/test/unit/components/copyToClipBoard.spec.js similarity index 85% rename from test/unit/webui/components/copyToClipBoard.spec.js rename to test/unit/components/copyToClipBoard.spec.js index 05b48ba..699ea01 100644 --- a/test/unit/webui/components/copyToClipBoard.spec.js +++ b/test/unit/components/copyToClipBoard.spec.js @@ -6,8 +6,8 @@ import React from 'react'; import { shallow } from 'enzyme'; -import CopyToClipBoard from '../../../../src/webui/components/CopyToClipBoard'; -import { CopyIcon } from '../../../../src/webui/components/CopyToClipBoard/styles'; +import CopyToClipBoard from '../../../src/webui/components/CopyToClipBoard/index'; +import { CopyIcon } from '../../../src/webui/components/CopyToClipBoard/styles'; describe(' component', () => { let wrapper; diff --git a/test/unit/webui/components/footer.spec.js b/test/unit/components/footer.spec.js similarity index 79% rename from test/unit/webui/components/footer.spec.js rename to test/unit/components/footer.spec.js index f584d21..5b78248 100644 --- a/test/unit/webui/components/footer.spec.js +++ b/test/unit/components/footer.spec.js @@ -2,9 +2,9 @@ import React from 'react'; import { mount } from 'enzyme'; -import Footer from '../../../../src/webui/components/Footer/index'; +import Footer from '../../../src/webui/components/Footer/index'; -jest.mock('../../../../package.json', () => ({ +jest.mock('../../../package.json', () => ({ version: '4.0.0-alpha.3' })); diff --git a/test/unit/webui/components/header.spec.js b/test/unit/components/header.spec.js similarity index 97% rename from test/unit/webui/components/header.spec.js rename to test/unit/components/header.spec.js index 6944734..5f322dd 100644 --- a/test/unit/webui/components/header.spec.js +++ b/test/unit/components/header.spec.js @@ -6,7 +6,7 @@ import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; import { shallow } from 'enzyme'; -import Header from '../../../../src/webui/components/Header'; +import Header from '../../../src/webui/components/Header/index'; describe('
component with logged in state', () => { let wrapper; diff --git a/test/unit/webui/components/help.spec.js b/test/unit/components/help.spec.js similarity index 81% rename from test/unit/webui/components/help.spec.js rename to test/unit/components/help.spec.js index af66b02..ae72677 100644 --- a/test/unit/webui/components/help.spec.js +++ b/test/unit/components/help.spec.js @@ -3,7 +3,7 @@ */ import React from 'react'; import { shallow } from 'enzyme'; -import Help from '../../../../src/webui/components/Help/index'; +import Help from '../../../src/webui/components/Help/index'; describe(' component', () => { diff --git a/test/unit/webui/components/login.spec.js b/test/unit/components/login.spec.js similarity index 98% rename from test/unit/webui/components/login.spec.js rename to test/unit/components/login.spec.js index 2d9bece..587fc6a 100644 --- a/test/unit/webui/components/login.spec.js +++ b/test/unit/components/login.spec.js @@ -6,7 +6,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import LoginModal from '../../../../src/webui/components/Login'; +import LoginModal from '../../../src/webui/components/Login/index'; const eventUsername = { target: { diff --git a/test/unit/webui/components/noitems.spec.js b/test/unit/components/noitems.spec.js similarity index 88% rename from test/unit/webui/components/noitems.spec.js rename to test/unit/components/noitems.spec.js index f327ad0..c66906b 100644 --- a/test/unit/webui/components/noitems.spec.js +++ b/test/unit/components/noitems.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; -import NoItems from '../../../../src/webui/components/NoItems/index'; +import NoItems from '../../../src/webui/components/NoItems/index'; console.error = jest.fn(); diff --git a/test/unit/webui/components/notfound.spec.js b/test/unit/components/notfound.spec.js similarity index 87% rename from test/unit/webui/components/notfound.spec.js rename to test/unit/components/notfound.spec.js index b8d6851..f006c19 100644 --- a/test/unit/webui/components/notfound.spec.js +++ b/test/unit/components/notfound.spec.js @@ -5,7 +5,7 @@ import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; import { shallow } from 'enzyme'; -import NotFound from '../../../../src/webui/components/NotFound/index'; +import NotFound from '../../../src/webui/components/NotFound/index'; console.error = jest.fn(); diff --git a/test/unit/webui/components/package.spec.js b/test/unit/components/package.spec.js similarity index 92% rename from test/unit/webui/components/package.spec.js rename to test/unit/components/package.spec.js index 0cd3dca..6dafa3b 100644 --- a/test/unit/webui/components/package.spec.js +++ b/test/unit/components/package.spec.js @@ -4,9 +4,9 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Package from '../../../../src/webui/components/Package/index'; -import Tag from '../../../../src/webui/components/Tag/index'; -import { Version, WrapperLink, Field, OverviewItem } from '../../../../src/webui/components/Package/styles'; +import Package from '../../../src/webui/components/Package/index'; +import Tag from '../../../src/webui/components/Tag/index'; +import { Version, WrapperLink, Field, OverviewItem } from '../../../src/webui/components/Package/styles'; /** diff --git a/test/unit/webui/components/packagelist.spec.js b/test/unit/components/packagelist.spec.js similarity index 91% rename from test/unit/webui/components/packagelist.spec.js rename to test/unit/components/packagelist.spec.js index ffc7afe..67ad9a5 100644 --- a/test/unit/webui/components/packagelist.spec.js +++ b/test/unit/components/packagelist.spec.js @@ -4,8 +4,8 @@ import React from 'react'; import { mount } from 'enzyme'; -import PackageList from '../../../../src/webui/components/PackageList/index'; -import Help from '../../../../src/webui/components/Help/index'; +import PackageList from '../../../src/webui/components/PackageList/index'; +import Help from '../../../src/webui/components/Help/index'; import { BrowserRouter } from 'react-router-dom'; describe(' component', () => { diff --git a/test/unit/webui/components/readme.spec.js b/test/unit/components/readme.spec.js similarity index 90% rename from test/unit/webui/components/readme.spec.js rename to test/unit/components/readme.spec.js index 87ba5d2..8c95cb2 100644 --- a/test/unit/webui/components/readme.spec.js +++ b/test/unit/components/readme.spec.js @@ -4,7 +4,7 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; -import Readme from '../../../../src/webui/components/Readme/index'; +import Readme from '../../../src/webui/components/Readme/index'; describe(' component', () => { test('should load the component in default state', () => { diff --git a/test/unit/webui/components/search.spec.js b/test/unit/components/search.spec.js similarity index 96% rename from test/unit/webui/components/search.spec.js rename to test/unit/components/search.spec.js index a1571ef..aa96c2d 100644 --- a/test/unit/webui/components/search.spec.js +++ b/test/unit/components/search.spec.js @@ -6,11 +6,11 @@ import React from 'react'; import { mount } from 'enzyme'; -import { Search } from '../../../../src/webui/components/Search/index'; +import { Search } from '../../../src/webui/components/Search/index'; -const SEARCH_FILE_PATH = '../../../../src/webui/components/Search/index'; -const API_FILE_PATH = '../../../../src/webui/utils/api'; -const URL_FILE_PATH = '../../../../src/webui/utils/url'; +const SEARCH_FILE_PATH = '../../../src/webui/components/Search/index'; +const API_FILE_PATH = '../../../src/webui/utils/api'; +const URL_FILE_PATH = '../../../src/webui/utils/url'; // Global mocks const event = { diff --git a/test/unit/webui/components/store/login.js b/test/unit/components/store/login.js similarity index 88% rename from test/unit/webui/components/store/login.js rename to test/unit/components/store/login.js index 4c4d027..2729bb9 100644 --- a/test/unit/webui/components/store/login.js +++ b/test/unit/components/store/login.js @@ -1,4 +1,4 @@ -import {API_ERROR} from '../../../../../src/lib/constants'; +import {API_ERROR} from '../../../../src/lib/constants'; /** * API mock for login endpoint * @param {object} config configuration of api call diff --git a/test/unit/webui/components/store/logo.js b/test/unit/components/store/logo.js similarity index 100% rename from test/unit/webui/components/store/logo.js rename to test/unit/components/store/logo.js diff --git a/test/unit/webui/components/store/package.js b/test/unit/components/store/package.js similarity index 100% rename from test/unit/webui/components/store/package.js rename to test/unit/components/store/package.js diff --git a/test/unit/webui/components/store/packageMeta.js b/test/unit/components/store/packageMeta.js similarity index 100% rename from test/unit/webui/components/store/packageMeta.js rename to test/unit/components/store/packageMeta.js diff --git a/test/unit/webui/utils/login.spec.js b/test/unit/utils/login.spec.js similarity index 97% rename from test/unit/webui/utils/login.spec.js rename to test/unit/utils/login.spec.js index 5f9fe08..faa48d5 100644 --- a/test/unit/webui/utils/login.spec.js +++ b/test/unit/utils/login.spec.js @@ -1,4 +1,4 @@ -import { isTokenExpire, makeLogin } from '../../../../src/webui/utils/login'; +import { isTokenExpire, makeLogin } from '../../../src/webui/utils/login'; import { generateTokenWithTimeRange, diff --git a/test/unit/webui/utils/package.spec.js b/test/unit/utils/package.spec.js similarity index 98% rename from test/unit/webui/utils/package.spec.js rename to test/unit/utils/package.spec.js index bd5e1b7..c6724cd 100644 --- a/test/unit/webui/utils/package.spec.js +++ b/test/unit/utils/package.spec.js @@ -5,7 +5,7 @@ import { formatDateDistance, getLastUpdatedPackageTime, getRecentReleases -} from '../../../../src/webui/utils/package'; +} from '../../../src/webui/utils/package'; import { packageMeta } from '../components/store/packageMeta'; diff --git a/yarn.lock b/yarn.lock index 01fc4ed..cd723d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4771,6 +4771,13 @@ enzyme-adapter-utils@^1.10.0: prop-types "^15.7.2" semver "^5.6.0" +enzyme-to-json@3.3.5: + version "3.3.5" + resolved "https://registry.verdaccio.org/enzyme-to-json/-/enzyme-to-json-3.3.5.tgz#f8eb82bd3d5941c9d8bc6fd9140030777d17d0af" + integrity sha512-DmH1wJ68HyPqKSYXdQqB33ZotwfUhwQZW3IGXaNXgR69Iodaoj8TF/D9RjLdz4pEhGq2Tx2zwNUIjBuqoZeTgA== + dependencies: + lodash "^4.17.4" + enzyme@3.9.0: version "3.9.0" resolved "https://registry.npmjs.org/enzyme/-/enzyme-3.9.0.tgz#2b491f06ca966eb56b6510068c7894a7e0be3909"