added tests
This commit is contained in:
parent
7d7bea7625
commit
6bb34f2cbd
16 changed files with 12955 additions and 191 deletions
47
__tests__/version.js
Normal file
47
__tests__/version.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const puppeteer = require('puppeteer');
|
||||
const { setup, teardown } = require('jest-dev-server');
|
||||
|
||||
let browser;
|
||||
let page;
|
||||
|
||||
beforeAll(async () => {
|
||||
browser = await puppeteer.launch();
|
||||
page = await browser.newPage();
|
||||
|
||||
return setup([
|
||||
{
|
||||
command: 'npm run demo:dev',
|
||||
port: 3000,
|
||||
},
|
||||
{
|
||||
command: 'npm run demo:prod',
|
||||
port: 3001,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
browser.close();
|
||||
|
||||
await teardown();
|
||||
});
|
||||
|
||||
describe('import.meta.env contains PACKAGE_VERSION', () => {
|
||||
test('in development', async () => {
|
||||
await page.goto('http://localhost:3000/');
|
||||
|
||||
const element = await page.$('#PACKAGE_VERSION');
|
||||
const version = await element.evaluate((el) => el.textContent);
|
||||
|
||||
expect(version).toBe('0.0.0');
|
||||
});
|
||||
|
||||
test('in production', async () => {
|
||||
await page.goto('http://localhost:3001/');
|
||||
|
||||
const element = await page.$('#PACKAGE_VERSION');
|
||||
const version = await element.evaluate((el) => el.textContent);
|
||||
|
||||
expect(version).toBe('0.0.0');
|
||||
});
|
||||
});
|
0
example/.gitignore → demo/.gitignore
vendored
0
example/.gitignore → demo/.gitignore
vendored
13
example/package-lock.json → demo/package-lock.json
generated
13
example/package-lock.json → demo/package-lock.json
generated
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "example",
|
||||
"name": "demo",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
|
@ -20,10 +20,15 @@
|
|||
}
|
||||
},
|
||||
"..": {
|
||||
"version": "0.0.4",
|
||||
"version": "1.0.0",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"jest": "^26.6.3",
|
||||
"jest-dev-server": "^5.0.0",
|
||||
"puppeteer": "^9.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsup": "^3.12.1",
|
||||
"typescript": "^4.1.5",
|
||||
"vite": "^2.0.0-beta.69"
|
||||
|
@ -1485,6 +1490,10 @@
|
|||
"vite-plugin-package-version": {
|
||||
"version": "file:..",
|
||||
"requires": {
|
||||
"jest": "^26.6.3",
|
||||
"jest-dev-server": "^5.0.0",
|
||||
"puppeteer": "^9.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsup": "^3.12.1",
|
||||
"typescript": "^4.1.5",
|
||||
"vite": "^2.0.0-beta.69"
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "example",
|
||||
"name": "demo",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview"
|
||||
"serve": "vite preview --port 3001"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^17.0.0",
|
|
@ -1,14 +1,15 @@
|
|||
import React, { useState } from 'react'
|
||||
import logo from './logo.svg'
|
||||
import './App.css'
|
||||
import React, { useState } from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
const [count, setCount] = useState(0)
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<div id="PACKAGE_VERSION">{import.meta.env.PACKAGE_VERSION}</div>
|
||||
<p>Hello Vite + React!</p>
|
||||
<p>
|
||||
<button onClick={() => setCount((count) => count + 1)}>
|
||||
|
@ -39,7 +40,7 @@ function App() {
|
|||
</p>
|
||||
</header>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default App
|
||||
export default App;
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
@ -3,8 +3,6 @@ import ReactDOM from 'react-dom';
|
|||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
console.log(import.meta.env);
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
|
@ -5,4 +5,8 @@ import loadVersion from 'vite-plugin-package-version';
|
|||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [reactRefresh(), loadVersion()],
|
||||
server: {
|
||||
port: 3000,
|
||||
strictPort: true,
|
||||
},
|
||||
});
|
4
jest.config.js
Normal file
4
jest.config.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// jest.config.js
|
||||
module.exports = {
|
||||
testTimeout: 10000,
|
||||
};
|
13043
package-lock.json
generated
13043
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
@ -20,16 +20,24 @@
|
|||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "rm -rf dist",
|
||||
"build": "npm run clean && tsup src/index.ts --dts",
|
||||
"clean": "rimraf {dist,package-lock.json,node_modules} && npm i",
|
||||
"test": "jest",
|
||||
"dev": "tsup src/index.ts --dts --watch",
|
||||
"dev:client": "npm -C example run dev",
|
||||
"prepublishOnly": "npm run build"
|
||||
"build": "rimraf dist && tsup src/index.ts --dts",
|
||||
"demo:clean": "rimraf demo/{dist,package-lock.json,node_modules} && npm -C demo install",
|
||||
"demo:dev": "npm -C demo run dev",
|
||||
"demo:prod": "npm -C demo run build && npm -C demo run serve",
|
||||
"prepublishOnly": "npm run build && npm run test",
|
||||
"postinstall": "npm run build"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": ">=2.0.0-beta.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^26.6.3",
|
||||
"jest-dev-server": "^5.0.0",
|
||||
"puppeteer": "^9.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsup": "^3.12.1",
|
||||
"typescript": "^4.1.5",
|
||||
"vite": "^2.0.0-beta.69"
|
||||
|
|
Loading…
Reference in a new issue