Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERC-6194: Improve test coverage, linting #23

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.css
src/server/tsconfig.server.json
src/cli/tsconfig.cli.json
src/services/__fixtures__
*.snap
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:react/recommended',
],
parserOptions: {
project: './tsconfig.json',
Expand All @@ -33,6 +34,7 @@ module.exports = {
"max-len": [1, 120, 4],
"no-plusplus": "off",
"global-require": "off",
"@typescript-eslint/explicit-function-return-type": "off",
},
overrides: [
{
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
roots: ["<rootDir>/src"],
preset: 'ts-jest',
testEnvironment: 'node',
testEnvironment: 'jsdom',
transform: {
'^.+\\.js$': 'babel-jest',
'.+\\.(css|styl|less|sass|scss)$': 'jest-transform-css',
Expand Down
50 changes: 20 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint": "eslint \"src/**/*\"",
"lint-fix": "eslint --fix \"src/**/*\"",
"test": "jest --coverage || true",
"test:updateSnapshot": "jest --updateSnapshot"
"test:updateSnapshot": "jest --updateSnapshot --silent"
},
"license": "MIT",
"dependencies": {
Expand Down Expand Up @@ -68,6 +68,7 @@
"@types/uuid": "^3.4.5",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"axios-mock-adapter": "^1.17.0",
"babel-eslint": "^10.0.0",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.0",
Expand Down
14 changes: 11 additions & 3 deletions src/client/components/App/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import React from 'react';

import { App } from './App';

const app = shallow(<App/>);

it('renders', () => {
expect(app).toMatchSnapshot();
const app = mount(<App/>);
expect(app.getDOMNode()).toMatchSnapshot();
});

describe('mountWidget', () => {
it('correctly mounts a widget', () => {
const app = mount(<App/>);
(app.instance() as App).mountWidget('<div>blah</div>');
expect(app.getDOMNode()).toMatchSnapshot();
});
});
3 changes: 2 additions & 1 deletion src/client/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class App extends Component<{}, {}> {

componentDidMount() {
this.socket = io(`${host}:${port}`);
this.socket.on('connect', () => console.log('Socket connected'));

this.socket.on('connect', () => console.log('Socket connected')); // eslint-disable-line no-console
this.socket.on('event', (data: SocketData) => {
this.mountWidget(data.html);
});
Expand Down
44 changes: 43 additions & 1 deletion src/client/components/App/__snapshots__/App.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports['renders 1'] = 'ShallowWrapper {}';
exports['mountWidget correctly mounts a widget 1'] = `
<div>
<div
class="styled__StyledFlex-hcvk8l-0 gzvNmR styled__StyledBox-sj5f1m-0 dWCHjG"
>
<img
height="34"
src="favicon.ico"
/>

<h1
class="styled__StyledH1-tqnj75-1 exiPoU"
>
Widget Builder
</h1>
</div>
<div>
<div>
blah
</div>
</div>
</div>
`;

exports['renders 1'] = `
<div>
<div
class="styled__StyledFlex-hcvk8l-0 gzvNmR styled__StyledBox-sj5f1m-0 dWCHjG"
>
<img
height="34"
src="favicon.ico"
/>

<h1
class="styled__StyledH1-tqnj75-1 exiPoU"
>
Widget Builder
</h1>
</div>
<div />
</div>
`;
2 changes: 1 addition & 1 deletion src/client/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './components/App/App';
import { App } from './components/App/App';

ReactDOM.render(
<App />,
Expand Down
34 changes: 34 additions & 0 deletions src/client/utils/__snapshots__/widget.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createElementFromHTML correctly creates an element 1`] = `
<div>
Hello
</div>
`;

exports[`executeWidgetScripts correctly clones a script 1`] = `
<div>


<script
data-test1="hi"
id="id1"
>

console.log("first")

</script>


<script
data-test1="hi2"
id="id2"
>

console.log("second")

</script>


</div>
`;
25 changes: 25 additions & 0 deletions src/client/utils/widget.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as widget from './widget';

describe('createElementFromHTML', () => {
it('correctly creates an element', () => {
const result = widget.createElementFromHTML('<div>Hello</div>');
expect(result).toMatchSnapshot();
});
});

describe('executeWidgetScripts', () => {
it('correctly clones a script', () => {
const widgetElement = document.createElement('div');
widgetElement.innerHTML = `
<script id="id1" data-test1="hi">
console.log("first")
</script>
<script id="id2" data-test1="hi2">
console.log("second")
</script>
`;

widget.executeWidgetScripts(widgetElement, document);
expect(widgetElement).toMatchSnapshot();
});
});
Loading