diff --git a/packages/components/.babelrc b/packages/components/.babelrc index b9a56e2..ce37735 100644 --- a/packages/components/.babelrc +++ b/packages/components/.babelrc @@ -1,5 +1,8 @@ { "env": { + "test": { + "presets": ["env", "react", "es2015"] + }, "development": { "presets": ["env", "react", "es2015"], "plugins": [ diff --git a/packages/components/.eslintrc b/packages/components/.eslintrc index 4ccec45..47b75d2 100644 --- a/packages/components/.eslintrc +++ b/packages/components/.eslintrc @@ -2,7 +2,7 @@ "parser": "babel-eslint", "extends": "airbnb", "env": { - "mocha": true + "jest": true }, "rules": { "comma-dangle": ["error", "only-multiline"], diff --git a/packages/components/package.json b/packages/components/package.json index 42b4b19..478939b 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -5,10 +5,10 @@ "main": "./lib/index.js", "scripts": { "clean": "rimraf lib", - "test": "npm run lint && npm run cover", + "test": "NODE_ENV=test npm run lint && npm run cover", "test:prod": "cross-env BABEL_ENV=production npm run test", - "test:only": "mocha --require babel-core/register --require babel-polyfill --recursive", - "cover": "istanbul cover _mocha -- --require babel-core/register --require babel-polyfill --recursive", + "test:only": "jest", + "cover": "NODE_ENV=test jest --coverage", "lint": "eslint src test", "build": "cross-env BABEL_ENV=production babel src --out-dir lib", "prepublish": "npm run clean && npm run test && npm run build" @@ -46,7 +46,6 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-minify": "^0.3.0", "babel-preset-react": "^6.24.1", - "chai": "^4.1.2", "cross-env": "^5.1.3", "enzyme": "^3.6.0", "enzyme-adapter-react-16": "^1.5.0", @@ -56,9 +55,8 @@ "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.4.0", "fluent-react": "^0.8.1", - "istanbul": "^1.0.0-alpha", + "jest": "^23.6.0", "lerna": "^3.4.3", - "mocha": "^5.0.0", "prop-types": "^15.6.2", "react": "^16.5.2", "react-dom": "^16.5.2", diff --git a/packages/components/test/Loc.test.js b/packages/components/test/Loc.test.js index b6631e8..28fd23a 100644 --- a/packages/components/test/Loc.test.js +++ b/packages/components/test/Loc.test.js @@ -1,4 +1,3 @@ -import { assert, expect } from 'chai'; import { MyComponent } from '../examples/components'; import { augmentLoc, Loc } from '../src/Loc'; import { makeLocalizedElement } from '../src/make-localized-element'; @@ -9,9 +8,9 @@ describe('augmentLoc', () => { const MyLocalizedComponent = makeLocalizedElement(MyComponent, { label: true }); const newLoc = augmentLoc({ MyLocalizedComponent }); const newTypes = new Set(Object.keys(newLoc)); - expect(newTypes.size).to.equal(existingTypes.size + 1, 'Component not added'); - assert(newTypes.has('MyLocalizedComponent'), 'New component not in keys'); - expect(newLoc.MyLocalizedComponent).to.deep.equal( + expect(newTypes.size).toEqual(existingTypes.size + 1); + expect(newTypes).toContain('MyLocalizedComponent'); + expect(newLoc.MyLocalizedComponent).toEqual( MyLocalizedComponent, 'newLoc value not expected' ); diff --git a/packages/components/test/__snapshots__/make-localized-element.test.js.snap b/packages/components/test/__snapshots__/make-localized-element.test.js.snap new file mode 100644 index 0000000..7dd56b0 --- /dev/null +++ b/packages/components/test/__snapshots__/make-localized-element.test.js.snap @@ -0,0 +1,451 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`makeLocalizedElement Applies the attrs 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): , + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": Object { + "alt": true, + }, + "children": , + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "img", + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": Object { + "alt": true, + }, + "children": , + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "img", + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + }, +} +`; + +exports[`makeLocalizedElement Applies the other props to the child 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): + child text + , + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

+ child text +

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": "child text", + "className": "title_header", + }, + "ref": null, + "rendered": "child text", + "type": "h1", + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

+ child text +

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": "child text", + "className": "title_header", + }, + "ref": null, + "rendered": "child text", + "type": "h1", + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + }, +} +`; + +exports[`makeLocalizedElement Makes an element wrapped in a Localized component 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): , + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + }, +} +`; + +exports[`makeLocalizedElement Spreads in the l10nJsx 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): , + } + } + />, + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

, + "id": "test", + "link": , + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "attrs": undefined, + "children":

, + "id": "test", + "link": , + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + }, +} +`; + +exports[`makeLocalizedElement Spreads in the l10nVars 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): , + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "$name": "Alice", + "$number": 123, + "attrs": undefined, + "children":

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "$name": "Alice", + "$number": 123, + "attrs": undefined, + "children":

, + "id": "test", + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "host", + "props": Object { + "children": undefined, + }, + "ref": null, + "rendered": null, + "type": "h1", + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + }, +} +`; diff --git a/packages/components/test/make-localized-element.test.js b/packages/components/test/make-localized-element.test.js index 060288f..d6d614e 100644 --- a/packages/components/test/make-localized-element.test.js +++ b/packages/components/test/make-localized-element.test.js @@ -1,6 +1,4 @@ import React from 'react'; -import { Localized } from 'fluent-react/compat'; -import { assert, expect } from 'chai'; import Enzyme, { shallow } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import { formatVars, makeLocalizedElement } from '../src/make-localized-element'; @@ -11,7 +9,7 @@ describe('formatVars', () => { it('formats the l10nVars variables for spreading into the Localized', () => { const l10nVars = { name: 'Alice', number: 123 }; const expectedOutput = { $name: 'Alice', $number: 123 }; - expect(formatVars(l10nVars)).to.deep.equal(expectedOutput); + expect(formatVars(l10nVars)).toEqual(expectedOutput); }); }); @@ -19,47 +17,27 @@ describe('makeLocalizedElement', () => { it('Makes an element wrapped in a Localized component', () => { const Component = makeLocalizedElement('h1'); const wrapper = shallow(); - const expectedOutput = ( - -

- - ); - assert(wrapper.contains(expectedOutput)); + expect(wrapper).toMatchSnapshot(); }); it('Applies the attrs', () => { const Component = makeLocalizedElement('img', { alt: true }); const wrapper = shallow(); - const expectedOutput = ( - - - - ); - assert(wrapper.contains(expectedOutput)); + expect(wrapper).toMatchSnapshot(); }); it('Spreads in the l10nVars', () => { const Component = makeLocalizedElement('h1'); const l10nVars = { name: 'Alice', number: 123 }; const wrapper = shallow(); - const expectedOutput = ( - -

- - ); - assert(wrapper.contains(expectedOutput)); + expect(wrapper).toMatchSnapshot(); }); it('Spreads in the l10nJsx', () => { const Component = makeLocalizedElement('h1'); const l10nJsx = { link: }; const wrapper = shallow(); - const expectedOutput = ( - }> -

- - ); - assert(wrapper.contains(expectedOutput)); + expect(wrapper).toMatchSnapshot(); }); it('Applies the other props to the child', () => { @@ -70,11 +48,6 @@ describe('makeLocalizedElement', () => { ); const wrapper = shallow(input); - const expectedOutput = ( - -

child text

-
- ); - assert(wrapper.contains(expectedOutput)); + expect(wrapper).toMatchSnapshot(); }); }); diff --git a/packages/components/test/pseudolocalize.test.js b/packages/components/test/pseudolocalize.test.js index 6f56242..25fc984 100644 --- a/packages/components/test/pseudolocalize.test.js +++ b/packages/components/test/pseudolocalize.test.js @@ -1,10 +1,9 @@ -import { assert } from 'chai'; import { pseudolocalize } from '../src'; describe('pseudolocalize', () => { - it('should transform a message', () => { + it.only('should transform a message', () => { const expectedOutput = 'Ƥẏŧħǿǿƞ'; - assert(pseudolocalize('Python') === expectedOutput); + expect(pseudolocalize('Python')).toEqual(expectedOutput); }); });