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

Adding Jest #40

Merged
merged 31 commits into from
Feb 14, 2018
Merged

Adding Jest #40

merged 31 commits into from
Feb 14, 2018

Conversation

gautamarora
Copy link
Contributor

@gautamarora gautamarora commented Jan 22, 2018

A exploratory PR for using Jest for testing and coverage.

Description

This PR replaces chai, mocha, sinon, nyc with jest.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore, documentation, cleanup

Related Issue

#37

Motivation and Context

Some of the pros of using Jest would be:

  • speed of testing
  • interactive watch mode
  • snapshot testing

How Has This Been Tested?

npm test
npm run test:watch

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation (if required).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

p.s. Force push closed my last PR #38 😞 , so creating a new one.

Copy link
Contributor

@taveras taveras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Jest is compelling, and I will add a few snapshot tests in a follow-up.

let's hold off on merging this until #19 is merged, in order to migrate its tests to Jest as well.

};
const data = { foo: 'bar' };
const { firstChild } = parseXML('<a x="1" y="two">hello</a>');
visitNode(firstChild, 0, converters, data);
sinon.assert.calledWith(converters.a, { x: '1', y: 'two' }, data);
expect(converters.a.mock.calls.length).toBe(1);
expect(converters.a.mock.calls[0][0]).toEqual({ x: '1', y: 'two' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, mocking in Jest will be different -- i like it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also write:

expect(converters.a).toHaveBeenCalledTimes(1);
expect(converters.a).toHaveBeenCalledWith({ x: '1', y: 'two' });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgoldrbx - yes, certainly. fixed.

package.json Outdated
@@ -15,7 +15,8 @@
"lint": "eslint .",
"prepublishOnly": "npm run clean && npm run build",
"pretest": "eslint .",
"test": "nyc mocha --require babel-register --recursive"
"test": "jest --silent=true",
"test-watch": "jest --silent=true --watch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v.minor, there's an extra space after jest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch :)

@@ -43,37 +41,37 @@ describe('XMLToReact class ', () => {
};

it('exports a module', () => {
expect(XMLToReact).to.be.a('function');
expect(XMLToReact).toEqual(expect.any(Function));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally i'm fine with (typeof x).toEqual('function') as a pattern as well - but the mater works too :)

expect(wrapper.exists()).to.equal(true);
expect(wrapper.find('.test > [fancy]')).to.have.length(1);
expect(visitNodeSpy.called).to.equal(true);
expect(wrapper.exists()).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about .toEqual(true) for equivalent testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will resolve to use just .toEqual(true)

@@ -82,8 +80,8 @@ describe('XMLToReact class ', () => {
const xmltoreact = new XMLToReact(converters);
const tree = xmltoreact.convert(badXML);

expect(tree).to.equal(null);
expect(visitNodeSpy.called).to.equal(false);
expect(tree).toEqual(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial - in some assertions below you use toBeNull - make it consistent? (i don't really care)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to .toEqual(null) everywhere

@@ -34,7 +32,7 @@ describe('helpers', () => {
bar: () => {},
baz: () => {},
};
expect(validateConverters(converters)).to.equal(true);
expect(validateConverters(converters)).toBeTruthy();
Copy link
Contributor

@pgoldrbx pgoldrbx Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my comments are still the same here - i'd like to see strict boolean assertion, .toEqual(true) for this and all below (everywhere)

expect(validateConverters(true)).to.equal(false);
expect(validateConverters(() => {})).to.equal(false);
expect(validateConverters(null)).to.equal(false);
expect(validateConverters()).not.toEqual(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we just expect .toEqual(false) in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Copy link
Contributor

@pgoldrbx pgoldrbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤡

taveras and others added 2 commits January 25, 2018 18:15
* add environment and dependency prerequisites to README.md

* change test command in readme

* updated prerequisites

* added testing and development environment details for CONTRIBUTING.md

* change prerequisites to read as a sentence

* Update CONTRIBUTING.md

* update attribution heading for CONTRIBUTORING.md
Copy link
Contributor

@pgoldrbx pgoldrbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! 🤡

@pgoldrbx
Copy link
Contributor

@gautamarora ah, codeship is failing on lint issues!


/home/rof/src/github.com/CondeNast/xml-to-react/jest.config.js
11:22  error  Missing trailing comma  comma-dangle
12:6   error  Missing trailing comma  comma-dangle

@pgoldrbx
Copy link
Contributor

pgoldrbx commented Feb 4, 2018

@gautamarora looks like this one is good to merge?

@gautamarora
Copy link
Contributor Author

@pgoldrbx - @taveras wanted to hold, his comment earlier...

let's hold off on merging this until #19 is merged, in order to migrate its tests to Jest as well.

* Move xmldom parsing to internal interface

* fix lint errors

* add changelog update
@pgoldrbx
Copy link
Contributor

pgoldrbx commented Feb 5, 2018

merged!

gautamarora and others added 16 commits February 5, 2018 12:48
 into feature/jest

* 'feature/jest' of https://github.com/CondeNast/xml-to-react:
  linter strikes again
  Updating mock call checks
  Fix linting issues
  Making jest go faster + have cov thresholds
  Fix "not equal to true" tests to be "equal to false"
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Adding Jest
 into feature/jest

* 'feature/jest' of https://github.com/CondeNast/xml-to-react:
  Fix linting issues
  Making jest go faster + have cov thresholds
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Adding Jest
  linter strikes again
  Updating mock call checks
  Fix linting issues
  Making jest go faster + have cov thresholds
  Fix "not equal to true" tests to be "equal to false"
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Replace toBeTruthy()/toBeNull() with strict boolean checks
  Adding Jest
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
- Initial Release
- Changed XML parsing to use an internal interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️ still part of our initial release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

package.json Outdated
@@ -15,7 +15,8 @@
"lint": "eslint .",
"prepublishOnly": "npm run clean && npm run build",
"pretest": "eslint .",
"test": "nyc mocha --require babel-register --recursive"
"test": "jest --silent=true",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial, extra space after jest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@@ -0,0 +1,33 @@
import { DOMParser } from 'xmldom';

export const ERR_INVALID_XML = 'XMLToReact: Unable to parse invalid XML input. Please input valid XML.';
Copy link
Contributor

@pgoldrbx pgoldrbx Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this not get rebased properly? is that why it's showing up in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, not sure what happened here, certainly was rebased.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a // eslint-disable-line no-console for the console.warn, but nothing else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... because this was merged to master already
a08a366

it's not a big deal but i guess you have a merge commit in here or something

Copy link
Contributor

@pgoldrbx pgoldrbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - a couple minor things but nothing blocking merge

Copy link
Contributor

@pgoldrbx pgoldrbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is good to go. let's do it!

@gautamarora gautamarora merged commit 5ffff5b into master Feb 14, 2018
@gautamarora gautamarora deleted the feature/jest branch February 14, 2018 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants