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

Switch router and web from esm to cjs. #290

Merged
merged 10 commits into from
Mar 21, 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
20 changes: 19 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,25 @@ module.exports = {
targets: {
browsers: TARGETS_BROWSERS,
},
modules: false,
},
],
],
plugins: [
[
'babel-plugin-auto-import',
{
declarations: [
{
// import { React } from 'react'
default: 'React',
path: 'react',
},
{
// import { PropTypes } from 'prop-types'
default: 'PropTypes',
path: 'prop-types',
},
],
},
],
],
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"@babel/node": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/runtime-corejs3": "^7.8.4",
"@babel/preset-env": "^7.8.4",
"@babel/preset-react": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
"@babel/runtime-corejs3": "^7.8.4",
"babel-plugin-auto-import": "^1.0.5",
"babel-plugin-module-resolver": "^4.0.0",
"jest": "^25.1.0",
"lerna": "^3.20.2",
Expand All @@ -23,11 +24,14 @@
"eslintConfig": {
"extends": "@redwoodjs/eslint-config"
},
"eslintIgnore": ["dist", "packages/api/importAll.macro.js"],
"eslintIgnore": [
"dist",
"packages/api/importAll.macro.js"
],
"scripts": {
"build": "NODE_ENV=production lerna run build",
"test": "lerna run test --stream -- --colors",
"lint": "yarn eslint './packages/'",
"lint:fix": "yarn eslint --fix './packages/'"
}
}
}
31 changes: 18 additions & 13 deletions packages/cli/src/commands/generate/templates/cell/test.js.template
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import { render, cleanup } from '@testing-library/react'
import { render, cleanup, screen } from '@testing-library/react'

import { Loading, Empty, Failure, Success } from './${pascalName}Cell'

describe('${pascalName}Cell', () => {
afterEach(() => {
cleanup()
})

it('Loading renders successfully', () => {
expect(() => {
render(<Loading />)
}).not.toThrow()
render(<Loading />)
// Use screen.debug() to see output.
expect(screen.queryByText('Loading...')).toBeInTheDocument()
})

it('Empty renders successfully', () => {
expect(() => {
render(<Empty />)
}).not.toThrow()
render(<Empty />)
expect(screen.queryByText('Empty')).toBeInTheDocument()
})

it('Failure renders successfully', () => {
expect(() => {
render(<Failure error={{ message: 'error message' }} />)
}).not.toThrow()
render(<Failure error={{ message: 'Oh no!' }} />)
expect(screen.queryByText('Error: Oh no!')).toBeInTheDocument()
})

it('Success renders successfully', () => {
expect(() => {
Success({ ${camelName}: { objectKey: 'objectValue' } })
}).not.toThrow()
render(
<Success userExample={{ ${camelName}: { objectKey: 'objectValue' } }} />
)
expect(
screen.queryByText('{"${camelName}":{"objectKey":"objectValue"}}')
).toBeInTheDocument()
})
})
18 changes: 12 additions & 6 deletions packages/cli/src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@ export const handler = async ({ app }) => {
const execCommands = {
api: {
cwd: `${BASE_DIR}/api`,
cmd:
'yarn jest --passWithNoTests --config ../node_modules/@redwoodjs/core/config/jest.config.api.js',
cmd: 'yarn jest',
args: [
'--passWithNoTests',
'--config ../node_modules/@redwoodjs/core/config/jest.config.api.js',
],
},
web: {
cwd: `${BASE_DIR}/web`,
cmd:
'yarn jest --passWithNoTests --config ../node_modules/@redwoodjs/core/config/jest.config.web.js',
cmd: 'yarn jest',
args: [
'--passWithNoTests',
'--config ../node_modules/@redwoodjs/core/config/jest.config.web.js',
],
},
}

const tasks = new Listr(
app.map((appName) => {
const { cwd, cmd } = execCommands[appName]
const { cmd, args, cwd } = execCommands[appName]
return {
title: `Running '${appName}' jest tests`,
task: () => {
return execa(cmd, undefined, {
return execa(cmd, args, {
stdio: 'inherit',
shell: true,
cwd,
Expand Down
8 changes: 7 additions & 1 deletion packages/core/config/jest.config.web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// used by cli `rw test` command
// note: rootDir is a workaround for jest working directory weirdness

const path = require('path')

module.exports = {
resolver: 'jest-directory-named-resolver',
rootDir: process.cwd(),
globals: {
__REDWOOD__API_PROXY_PATH: '/',
},
setupFilesAfterEnv: [path.resolve(__dirname, './jest.setup.web.js')],
}
1 change: 1 addition & 0 deletions packages/core/config/jest.setup.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('@testing-library/jest-dom')
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@redwoodjs/dev-server": "^0.2.5",
"@redwoodjs/eslint-config": "^0.2.5",
"@redwoodjs/internal": "^0.2.5",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.5.0",
"@types/jest": "^25.1.3",
"@types/node": "^13.7.7",
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ module.exports = {
'jsx-a11y',
'react',
'react-hooks',
'jest-dom',
'@redwoodjs/redwood',
],
ignorePatterns: ['node_modules', 'dist'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'plugin:jest-dom/recommended',
'prettier/react',
],
overrides: [
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.0",
"eslint-plugin-jest-dom": "^2.0.1",
"prettier": "^1.19.1"
},
"gitHead": "2801c132f40263f9fcfbdac8b1750d2e423eb649"
Expand Down
5 changes: 4 additions & 1 deletion packages/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"files": [
"dist"
],
"module": "dist/index.js",
"main": "dist/index.js",
"license": "MIT",
"dependencies": {
"core-js": "3.6.4"
},
"peerDependencies": {
"react": "*"
},
"scripts": {
"build": "yarn clean && babel src -d dist",
"build:watch": "nodemon --ignore dist --exec 'yarn build'",
Expand Down
6 changes: 5 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"files": [
"dist"
],
"module": "dist/index.js",
"main": "dist/index.js",
"license": "MIT",
"dependencies": {
"@apollo/react-components": "^3.1.3",
Expand All @@ -20,6 +20,10 @@
"proptypes": "^1.1.0",
"react-hook-form": "^4.10.1"
},
"peerDependencies": {
"react": "*",
"prop-types": "*"
},
"scripts": {
"build": "yarn clean && babel src -d dist",
"build:watch": "nodemon --ignore dist --exec 'yarn build'",
Expand Down
Loading