Skip to content

chore: add create-react-app test #22

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

Open
wants to merge 1 commit into
base: default
Choose a base branch
from
Open
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
23 changes: 4 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
"scripts": {
"test:node": "mocha test/test-*.spec.js",
"test:browser": "playwright-test test/test-*.js",
"test:react-native": "jest test/test-lib.react-native.spec.js",
"test:react-native": "npm test --prefix test/react-native",
Copy link
Contributor

Choose a reason for hiding this comment

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

We can fix windows CI errors with this.

Suggested change
"test:react-native": "npm test --prefix test/react-native",
"test:react-native": "cd test/react-native && npm test",

"test:create-react-app": "npm test --prefix test/create-react-app",
Copy link
Contributor

Choose a reason for hiding this comment

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

same with the above suggestion.

Suggested change
"test:create-react-app": "npm test --prefix test/create-react-app",
"test:create-react-app": "cd test/create-react-app && npm test",

"test:es": "mocha test/test-lib.spec.mjs",
"test:cjs": "npm run test:node && npm run test:browser",
"test:types:ts": "npm test --prefix test/ts-use",
"test:types:esm": "npm test --prefix test/esm-use",
"test:types:cjs": "npm test --prefix test/cjs-use",
"test:types": "npm run test:types:ts && npm run test:types:esm && npm run test:types:cjs",
"test": "npm run test:es && npm run test:cjs && npm run test:react-native && npm run test:types"
"test": "npm run test:es && npm run test:cjs && npm run test:types && npm run test:create-react-app && npm run test:react-native"
},
"license": "MIT",
"author": "Irakli Gozalishvili <[email protected]>",
Expand All @@ -37,26 +38,10 @@
},
"devDependencies": {
"assert": "^2.0.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"mocha": "8.3.2",
"playwright-test": "2.1.0",
"react-native": "^0.63.4"
"playwright-test": "2.1.0"
},
"optionalDependencies": {
"@zxing/text-encoding": "0.9.0"
},
"jest": {
"preset": "react-native",
"transform": {
"\\.js$": [
"babel-jest",
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
]
}
}
}
4 changes: 2 additions & 2 deletions test/cjs-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "cjs-use",
"private": true,
"dependencies": {
"web-encoding": "file:../.."
"web-encoding": "file:../../"
},
"scripts": {
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
"test": "npm rm -rf ../../node_modules && npm install && tsc --noEmit --allowJs --checkJs src/main.js"
},
"devDependencies": {
"typescript": "^4.2.3"
Expand Down
1 change: 1 addition & 0 deletions test/create-react-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
23 changes: 23 additions & 0 deletions test/create-react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
39 changes: 39 additions & 0 deletions test/create-react-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "create-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-encoding": "file:../..",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "npm rm -rf ../../node_modules && npm install && react-scripts test a --watchAll=false",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
17 changes: 17 additions & 0 deletions test/create-react-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
9 changes: 9 additions & 0 deletions test/create-react-app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions test/create-react-app/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
23 changes: 23 additions & 0 deletions test/create-react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TextEncoder, TextDecoder } from "web-encoding";

function App() {
return (
<div className="App">
<header className="App-header">
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
{new TextDecoder().decode(new TextEncoder().encode('Learn React'))}
</a>
</header>
</div>
);
}

export default App;
8 changes: 8 additions & 0 deletions test/create-react-app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
16 changes: 16 additions & 0 deletions test/create-react-app/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
13 changes: 13 additions & 0 deletions test/create-react-app/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};

export default reportWebVitals;
5 changes: 5 additions & 0 deletions test/create-react-app/src/setupTests.js
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
import '@testing-library/jest-dom';
4 changes: 2 additions & 2 deletions test/esm-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "esm-use",
"private": true,
"dependencies": {
"web-encoding": "file:../.."
"web-encoding": "file:../../"
},
"scripts": {
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
"test": "npm rm -rf ../../node_modules && npm install && tsc --noEmit --allowJs --checkJs src/main.js"
},
"devDependencies": {
"typescript": "^4.2.3"
Expand Down
30 changes: 30 additions & 0 deletions test/react-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"private": true,
"version": "0.0.0",
"name": "react-native-tests",
"dependencies": {
"web-encoding": "file:../../"
},
"devDependencies": {
"assert": "^2.0.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-native": "^0.63.4"
},
"scripts": {
"test": "npm rm -rf ../../node_modules && npm install && jest test-lib.react-native.spec.js"
},
"jest": {
"preset": "react-native",
"transform": {
"\\.js$": [
"babel-jest",
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { TextEncoder, TextDecoder } = require("../src/lib.react-native.js")
const { TextEncoder, TextDecoder } = require("web-encoding")
const assert = require("assert")

describe("text encode/decode", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/ts-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "ts-use",
"private": true,
"dependencies": {
"web-encoding": "file:../.."
"web-encoding": "file:../../"
},
"scripts": {
"test": "npm install && tsc --noEmit"
"test": "npm rm -rf ../../node_modules && npm install && tsc --noEmit"
},
"devDependencies": {
"typescript": "^4.2.3"
Expand Down
Loading