-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/replace ava nyc enzyme and sinon for jest #8
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
base: develop
Are you sure you want to change the base?
Changes from all commits
339c43b
bf97c4f
5a47223
cfc17f0
a00f863
3b70703
5509a8a
c391ac7
0a54fd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| const testConfig = { | ||
| presets: [ | ||
| [ | ||
| '@babel/preset-env', | ||
| { | ||
| targets: { | ||
| node: 'current', | ||
| }, | ||
| }, | ||
| ], | ||
| '@babel/preset-react', | ||
| ], | ||
| }; | ||
|
|
||
| const config = { | ||
| presets: [ | ||
| [ | ||
| '@babel/preset-env', | ||
| { | ||
| targets: { | ||
| ie: '11', | ||
| }, | ||
| useBuiltIns: 'usage', | ||
| }, | ||
| ], | ||
| '@babel/preset-react', | ||
| ], | ||
| plugins: [ | ||
| '@babel/plugin-syntax-dynamic-import', | ||
| '@babel/plugin-proposal-class-properties', | ||
| '@babel/plugin-proposal-export-namespace-from', | ||
| ], | ||
| }; | ||
|
|
||
| module.exports = (api) => { | ||
| const isTest = api.env('test'); | ||
| if (isTest) return testConfig; | ||
|
|
||
| return config; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,10 @@ | |
| "description": "React utilities for internationalization", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text ava", | ||
| "test:watch": "cross-env NODE_ENV=test ava --watch", | ||
| "test": "jest --watch", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally the test script, must be a self terminated command in order to keep the expected behaviour for some CI runners (execute -> read exit code). I suggest create the opposite way (test:watch) also npm provides a method to call a script and pass parameters to the internal command. (npm test -- --watch)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In reallity I want to do a diferent approach, I want to make |
||
| "test:nowatch": "jest", | ||
| "postbuild": "./scripts/nlink lib", | ||
| "build": "babel src --out-dir lib --ignore **/*.spec.js", | ||
| "build": "babel src --out-dir lib --ignore **/*.test.js", | ||
| "prepublishOnly": "npm run build", | ||
| "prepack": "npm run build", | ||
| "lint": "eslint src", | ||
|
|
@@ -21,7 +21,7 @@ | |
| "husky": { | ||
| "hooks": { | ||
| "pre-commit": "npm run lint", | ||
| "pre-push": "npm run lint && npm test" | ||
| "pre-push": "npm run lint && npm run test:nowatch" | ||
| } | ||
| }, | ||
| "keywords": [ | ||
|
|
@@ -47,41 +47,6 @@ | |
| } | ||
| ], | ||
| "license": "MIT", | ||
| "babel": { | ||
| "presets": [ | ||
| [ | ||
| "@babel/preset-env", | ||
| { | ||
| "targets": { | ||
| "ie": "11" | ||
| }, | ||
| "useBuiltIns": "usage" | ||
| } | ||
| ], | ||
| "@babel/preset-react" | ||
| ], | ||
| "plugins": [ | ||
| "@babel/plugin-syntax-dynamic-import", | ||
| "@babel/plugin-proposal-class-properties", | ||
| "@babel/plugin-proposal-export-namespace-from" | ||
| ] | ||
| }, | ||
| "ava": { | ||
| "files": [ | ||
| "src/**/*.spec.js" | ||
| ], | ||
| "require": [ | ||
| "@babel/register", | ||
| "./test/shims" | ||
| ] | ||
| }, | ||
| "nyc": { | ||
| "exclude": [ | ||
| "src/**/index.js", | ||
| "src/**/*.spec.js", | ||
| "test" | ||
| ] | ||
| }, | ||
| "dependencies": { | ||
| "hoist-non-react-statics": "^3.3.0", | ||
| "memoize-one": "^5.0.0" | ||
|
|
@@ -96,27 +61,55 @@ | |
| "@babel/preset-react": "^7.0.0", | ||
| "@babel/register": "^7.0.0", | ||
| "@k14v/i18njs": "0.0.8", | ||
| "ava": "^1.2.1", | ||
| "babel-eslint": "^10.0.1", | ||
| "browser-env": "^3.2.5", | ||
| "cross-env": "^5.2.0", | ||
| "enzyme": "^3.8.0", | ||
| "enzyme-adapter-react-16": "^1.9.1", | ||
| "@testing-library/jest-dom": "^5.3.0", | ||
| "@testing-library/react": "^10.0.1", | ||
| "@testing-library/user-event": "^10.0.0", | ||
| "babel-eslint": "^10.1.0", | ||
| "babel-jest": "^25.2.3", | ||
| "babel-loader": "8.0.6", | ||
| "babel-plugin-named-asset-import": "^0.3.6", | ||
| "babel-preset-react-app": "^9.1.1", | ||
| "eslint": "^5.13.0", | ||
| "eslint-config-airbnb": "^17.1.0", | ||
| "eslint-plugin-import": "^2.16.0", | ||
| "eslint-plugin-jsx-a11y": "^6.1.1", | ||
| "eslint-plugin-react": "^7.12.4", | ||
| "husky": "^1.3.1", | ||
| "nyc": "^13.2.0", | ||
| "jest": "^25.2.3", | ||
| "jest-environment-jsdom-fourteen": "^1.0.1", | ||
| "jest-resolve": "^25.2.3", | ||
| "prop-types": "^15.7.2", | ||
| "react": "^16.8.4", | ||
| "react-dom": "^16.8.4", | ||
| "sinon": "^7.2.3" | ||
| "react": "^16.13.1", | ||
| "react-dom": "^16.13.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "prop-types": "^15.7.2", | ||
| "react": "^16.8.4", | ||
| "react-dom": "^16.8.4" | ||
| }, | ||
| "jest": { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems some configurations can be simplfied |
||
| "roots": [ | ||
| "<rootDir>/src" | ||
| ], | ||
| "collectCoverageFrom": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redudant theres no other format inside src directory |
||
| "src/**/*.{js,jsx}" | ||
| ], | ||
| "setupFilesAfterEnv": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has a previous review to see if is really need it |
||
| "<rootDir>/src/setupTests.js" | ||
| ], | ||
| "testMatch": [ | ||
| "<rootDir>/src/**/__tests__/**/*.{js,jsx}", | ||
| "<rootDir>/src/**/*.test.{js,jsx}" | ||
| ], | ||
| "testEnvironment": "jest-environment-jsdom-fourteen", | ||
| "transform": { | ||
| "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case the project is not and react app so there's no other kind of files rather than js
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to have the same config in all the projects, not just the bare minimun |
||
| }, | ||
| "transformIgnorePatterns": [ | ||
| "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$" | ||
| ], | ||
| "modulePaths": [ | ||
| "<rootDir>/src" | ||
| ] | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Core | ||
| import React from 'react'; | ||
| // Testing | ||
| import { render } from '@testing-library/react'; | ||
| import { Consumer } from './testUtils'; | ||
|
|
||
|
|
||
| describe('I18nConsumer', () => { | ||
|
|
||
| it('should throw a warning, when try to use a consumer without provider', () => { | ||
| jest.spyOn(console, 'warn'); | ||
| render(<Consumer />); | ||
| expect(console.warn).toBeCalledTimes(1); | ||
| console.warn.mockRestore(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would be more precise if the test checks the content of the message
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rigth, I will make the change |
||
| }); | ||
|
|
||
| }); | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Core | ||
| import React from 'react'; | ||
| // Testing | ||
| import { render } from '@testing-library/react'; | ||
| import { fetchI18n, Consumer } from './testUtils'; | ||
| // Components | ||
| import I18nProvider from './I18nProvider'; | ||
|
|
||
|
|
||
| describe('I18nProvider', () => { | ||
| it('render without errors', async () => { | ||
| const i18n = await fetchI18n(); | ||
| render(<I18nProvider i18n={i18n}><Consumer /></I18nProvider>); | ||
| }); | ||
|
|
||
| it('translates correctly', async () => { | ||
| const i18n = await fetchI18n(); | ||
| const { getByText } = render(<I18nProvider i18n={i18n}><Consumer word="Teléfono" /></I18nProvider>); | ||
| expect(getByText('Phone')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('updates correctly after setLocale', async () => { | ||
| const i18n = await fetchI18n(); | ||
| const { getByText, rerender } = render(<I18nProvider i18n={i18n}><Consumer word="Teléfono" /></I18nProvider>); | ||
| expect(getByText('Phone')).toBeInTheDocument(); | ||
| await i18n.setLocale('de'); | ||
| rerender(<I18nProvider i18n={i18n}><Consumer word="Teléfono" /></I18nProvider>); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that error is resolved in a future PR |
||
| expect(getByText('Telefon')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
| // allows you to do things like: | ||
| // expect(element).toHaveTextContent(/react/i) | ||
| // learn more: https://github.com/testing-library/jest-dom | ||
| require('@testing-library/jest-dom/extend-expect'); |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature seems to try to resolve a conditional environment setting,
To preserve the project settings as much as possible and keep it centralized, I suggest follow the previous method using a Babel feature to solve this problem.
https://babeljs.io/docs/en/6.26.3/babelrc#env-option
Also recommend not include this commit to keep the tree changes clean and simple (rebase from the begining of this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find any way to do this with
package.json, can you show me a example?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the configuration available in .babelrc are compatible inside the package.sjon babel declaration.
https://babeljs.io/docs/en/6.26.3/babelrc#use-via-packagejson
{ "babel": { "env": { // Specific configuration for each enviroment "test": { .... } } } }