Skip to content

Commit

Permalink
Enhance e2e test suite (#208)
Browse files Browse the repository at this point in the history
* Enhance e2e test suite

* test depends on build now

* lint too
  • Loading branch information
tizmagik authored Oct 17, 2022
1 parent 6380e1f commit 874b478
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"build": "babel --out-dir build src --ignore src/__tests__ --source-maps --delete-dir-on-start --minified --no-comments",
"build:watch": "npm run build -- --watch",
"lint": "eslint ./src",
"prepare": "husky install && npm run lint && npm run test && npm run build",
"prepare": "husky install && npm run build && npm run lint && npm run test",
"test": "jest",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch"
Expand Down
28 changes: 23 additions & 5 deletions src/__tests__/e2e.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/* eslint-disable react/destructuring-assignment,react/no-multi-comp,react/prop-types,react/prefer-stateless-function */
/* eslint-disable jsx-a11y/control-has-associated-label */
/* eslint-disable global-require */
import React, { useContext } from 'react';
import { mount } from 'enzyme';
import PropTypes from 'prop-types';
import hoistNonReactStatics from 'hoist-non-react-statics';

const dispatchTrackingEvent = jest.fn();
jest.setMock('../dispatchTrackingEvent', dispatchTrackingEvent);
window.dataLayer = [];
window.dataLayer.push = dispatchTrackingEvent;

const testDataContext = { testDataContext: true };
const testData = { testData: true };
const dispatch = jest.fn();
const testState = { booleanState: true };

describe('e2e', () => {
// eslint-disable-next-line global-require
const { default: track, useTracking } = require('..');
const runTests = useBuiltLib => {
const { default: track, useTracking } = useBuiltLib
? require('../../build')
: require('..');

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -736,7 +739,10 @@ describe('e2e', () => {
});

it('root context items are accessible to children', () => {
const ReactTrackingContext = require('../ReactTrackingContext').default; // eslint-disable-line global-require
const ReactTrackingContext = (useBuiltLib
? require('../../build/ReactTrackingContext')
: require('../ReactTrackingContext')
).default;

const App = track()(() => {
return <Child />;
Expand Down Expand Up @@ -922,4 +928,16 @@ describe('e2e', () => {
expect(parent.instance().child).not.toBeNull();
expect(focusFn).toHaveBeenCalledTimes(1);
});
};

describe('e2e', () => {
if (process.env.SKIP_BUILT_LIB_CHECK !== 'true') {
describe('with built lib', () => {
runTests(true);
});
}

describe('with source lib', () => {
runTests(false);
});
});

0 comments on commit 874b478

Please sign in to comment.