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

feat: simplify vite server #15416

Merged
merged 59 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5c3c184
feat: simplify vite server
elevatebart Mar 11, 2021
1b1a67b
fix: make CI work
elevatebart Mar 11, 2021
a8331e5
remove weird changes
elevatebart Mar 11, 2021
fcaba49
wip: try error management
elevatebart Mar 12, 2021
f98a0af
fix: fill in mime types
elevatebart Mar 12, 2021
42344b9
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 13, 2021
c456dde
fix: update version of vite
elevatebart Mar 16, 2021
2cc136e
fix: make styles work
elevatebart Mar 17, 2021
493eed3
adjusting for vue 3 tests too
elevatebart Mar 17, 2021
7ad993b
make vue & react work
elevatebart Mar 17, 2021
39c7e53
remove bad option
elevatebart Mar 17, 2021
31c7215
refactor: simplify url forwarding
elevatebart Mar 17, 2021
905fa6b
fix: use vite server to transform html
elevatebart Mar 17, 2021
aa6494d
Merge branch 'develop' into feat/vite-error-management
Mar 17, 2021
d052125
rollback unwanted changes
elevatebart Mar 17, 2021
db83700
display errors correctly
elevatebart Mar 17, 2021
9f81b72
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 17, 2021
f67e60d
reactor: move some files around
elevatebart Mar 17, 2021
26d59c9
rename file typo
elevatebart Mar 18, 2021
db59ff9
fix comments
elevatebart Mar 18, 2021
57cd0da
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 19, 2021
6763db6
build: report vite tests on circle
elevatebart Mar 19, 2021
ca4f052
fix: vite client for specs
elevatebart Mar 19, 2021
736e738
tests: add vue support file
elevatebart Mar 19, 2021
e9e51bc
docs: extract vite.config for better example
elevatebart Mar 19, 2021
b56403a
fix: add png support examples
elevatebart Mar 19, 2021
6fe80da
chore: add some comments to the init file
elevatebart Mar 19, 2021
1e746a6
build: use vue2 tests with vite to avoid conflicts
elevatebart Mar 19, 2021
a243077
refactor: simplify cy vite plugin
elevatebart Mar 19, 2021
fc4ecbe
refactor: final cleanup
elevatebart Mar 19, 2021
0032108
feat: make viewport bigger when error
elevatebart Mar 19, 2021
5f8e513
fix: eat compile errors
elevatebart Mar 20, 2021
5a99031
fix: setup support for testing library
elevatebart Mar 20, 2021
90dbee0
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 20, 2021
aaa26f1
catch import errors
elevatebart Mar 20, 2021
bfff6b4
build: use viet in the design system
elevatebart Mar 20, 2021
9d8c5b8
fix design system quirks
elevatebart Mar 20, 2021
107c9a4
fix: delay async component to make tets more stable
elevatebart Mar 21, 2021
bdc3a18
adapt rollup dev server to new architecture
elevatebart Mar 21, 2021
2c07d5a
remove hacks since they don't work
elevatebart Mar 22, 2021
c74dcdd
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 25, 2021
1b3c956
fix: load normally
elevatebart Mar 26, 2021
e3d01ce
update vitejs
elevatebart Mar 26, 2021
0345ca3
avoid need to hae an html file at root
elevatebart Mar 26, 2021
ebd5fea
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 26, 2021
88d0815
publish html file
elevatebart Mar 26, 2021
f73aae6
fix vite server
elevatebart Mar 26, 2021
f6c8786
fix: avoid error when vite cannot annalyze pure dynamic dependency
elevatebart Mar 26, 2021
5c33498
add an extra vue spec
elevatebart Mar 26, 2021
63ee608
store videos in ci
elevatebart Mar 26, 2021
1b74f7f
videos path update
elevatebart Mar 26, 2021
6b15fc7
remove data-cy
elevatebart Mar 26, 2021
25d9a89
reorder tests to see if they pass
elevatebart Mar 27, 2021
937f04c
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 30, 2021
86a3b85
use vue3 as a showcase
elevatebart Mar 31, 2021
215b722
make a local version of vue 2
elevatebart Mar 31, 2021
65bfa76
remove unnecessary change
elevatebart Mar 31, 2021
b85c2a8
Merge branch 'develop' into feat/vite-error-management
elevatebart Mar 31, 2021
a75f168
Merge branch 'develop' into feat/vite-error-management
Mar 31, 2021
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
8 changes: 7 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,13 @@ jobs:
at: ~/
- run:
name: Run tests
command: yarn workspace @cypress/vite-dev-server test
command: yarn test --reporter cypress-circleci-reporter --reporter-options resultsDir=./test_results
working_directory: npm/vite-dev-server
- store_test_results:
path: npm/vite-dev-server/test_results
- store_artifacts:
path: npm/vite-dev-server/cypress/videos
- store-npm-logs

npm-rollup-dev-server:
<<: *defaults
Expand Down
1 change: 0 additions & 1 deletion npm/design-system/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
"**/__image_snapshots__/*"
],
"componentFolder": "src",
"experimentalFetchPolyfill": true,
"fixturesFolder": false
}
65 changes: 2 additions & 63 deletions npm/design-system/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
// @ts-check
const { startDevServer } = require('@cypress/webpack-dev-server')
const path = require('path')
const babelConfig = require('../../babel.config.js')

/** @type import("webpack").Configuration */
const webpackConfig = {
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.scss', '.css'],
},
mode: 'development',
devtool: false,
output: {
publicPath: '/',
chunkFilename: '[name].bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx|mjs|ts|tsx)$/,
loader: 'babel-loader',
options: { ...babelConfig, cacheDirectory: path.resolve(__dirname, '..', '..', '.babel-cache') },
},
{
test: /\.modules?\.s[ac]ss$/i,
exclude: [/node_modules/],
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
'sass-loader',
],
},
{
test: /\.s[ac]ss$/i,
exclude: [/node_modules/, /\.modules?\.s[ac]ss$/i],
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
// some of our examples import SVG
test: /\.svg$/,
loader: 'svg-url-loader',
},
{
// some of our examples import SVG
test: /\.svg$/,
loader: 'svg-url-loader',
},
{
test: /\.(png|jpg)$/,
use: ['file-loader'],
},
{
test: /\.(svg|eot|woff|woff2|ttf)$/,
use: ['file-loader'],
},
],
},
}
const { startDevServer } = require('@cypress/vite-dev-server')

/**
* @type Cypress.PluginConfig
*/
module.exports = (on, config) => {
on('dev-server:start', (options) => startDevServer({ options, webpackConfig, disableLazyCompilation: false }))
on('dev-server:start', (options) => startDevServer({ options }))

return config
}
11 changes: 11 additions & 0 deletions npm/design-system/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>AUT Frame</title>
</head>
<body>
</body>
</html>
7 changes: 2 additions & 5 deletions npm/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@babel/preset-react": "7.0.0",
"@babel/preset-typescript": "7.10.4",
"@cypress/react": "0.0.0-development",
"@cypress/webpack-dev-server": "0.0.0-development",
"@cypress/vite-dev-server": "0.0.0-development",
"@percy/cypress": "2.3.2",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-image": "2.0.6",
Expand All @@ -53,11 +53,8 @@
"rollup-plugin-postcss-modules": "2.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"sass": "1.32.8",
"sass-loader": "10.1.1",
"style-loader": "0.23.1",
"svg-url-loader": "3.0.3",
"typescript": "4.0.3",
"webpack": "4.44.1"
"vite": "2.1.3"
},
"peerDependencies": {
"react": "^=16.x || ^=17.x",
Expand Down
25 changes: 23 additions & 2 deletions npm/rollup-dev-server/index-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,34 @@
return node
}

/**
* Format the requested spec file.
* Nollup writes everything to a single directory (eg /dist)
* All outputted files are *.js.
* RunnerCt requests specs using the original filename including extension.
*
* Example usage:
* formatSpecName('/cypress/component/foo.spec.tsx') //=> 'foo.spec.js'
*/
function formatSpecName (filename) {
const split = filename.split('/')
const name = split[split.length - 1]
const pos = name.lastIndexOf('.')
const newName = `${name.substr(0, pos < 0 ? name.length : pos)}.js`

return `/${newName}`
}

const Cypress = window.Cypress = parent.Cypress

const specPath = `/__cypress/src/${formatSpecName(window.location.pathname)}`

const importsToLoad = [
() => import('{{{specPath}}}'),
() => {
{{{supportFile}}}
}
},
() => import(specPath),

]

Cypress.onSpecWindow(window, importsToLoad)
Expand Down
2 changes: 1 addition & 1 deletion npm/rollup-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsc",
"build-prod": "tsc",
"cy:open": "node ../../scripts/start.js --component-testing --project ${PWD}",
"cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
"cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
"test": "yarn cy:run",
"watch": "tsc -w"
Expand Down
27 changes: 2 additions & 25 deletions npm/rollup-dev-server/src/makeHtmlPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,11 @@ import { Express } from 'express'
const indexHtmlPath = resolve(__dirname, '../index-template.html')
const readIndexHtml = () => readFileSync(indexHtmlPath).toString()

/**
* Rormat the requested spec file.
* Nollup writes everything to a single directory (eg /dist)
* All outputted files are *.js.
* RunnerCt requests specs using the original filename including extension.
*
* Example usage:
* formatSpecName('/cypress/component/foo.spec.tsx') //=> 'foo.spec.js'
*/
function formatSpecName (publicPath: string, filename: string) {
const split = filename.split('/')
const name = split[split.length - 1]
const pos = name.lastIndexOf('.')
const newName = `${name.substr(0, pos < 0 ? name.length : pos)}.js`

return `${publicPath}/${newName}`
}

function handleIndex (indexHtml: string, publicPath: string, supportFilePath: string, cypressSpecPath: string) {
const specPath = `/${cypressSpecPath}`

console.log(supportFilePath)
function handleIndex (indexHtml: string, projectRoot: string, supportFilePath: string) {
const supportFile = readFileSync(supportFilePath).toString()

return render(indexHtml, {
supportFile,
specPath: formatSpecName(publicPath, specPath),
})
}

Expand All @@ -47,9 +25,8 @@ export const makeHtmlPlugin = (
server.use(`${publicPath}/index.html`, (req, res) => {
const html = handleIndex(
indexHtml,
publicPath,
projectRoot,
supportFilePath,
req.headers.__cypress_spec_path as string,
)

res.end(html)
Expand Down
48 changes: 48 additions & 0 deletions npm/vite-dev-server/client/initCypressTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This file is merged in a <script type=module> into index.html
// it will be used to load and kick start the selected spec

const supportPath = import.meta.env.__cypress_supportPath
const originAutUrl = import.meta.env.__cypress_originAutUrl

const specPath = window.location.pathname.replace(originAutUrl, '')

const importsToLoad = [() => import(/* @vite-ignore */ specPath)]

if (supportPath) {
importsToLoad.unshift(() => import(/* @vite-ignore */ supportPath))
}

const CypressInstance = window.Cypress = parent.Cypress

if (!CypressInstance) {
throw new Error('Tests cannot run without a reference to Cypress!')
}

// load the support and spec
CypressInstance.onSpecWindow(window, importsToLoad)

// then start the test process
CypressInstance.action('app:window:before:load', window)

// Before all tests we are mounting the root element,
// Cleaning up platform between tests is the responsibility of the specific adapter
// because unmounting react/vue component should be done using specific framework API
// (for devtools and to get rid of global event listeners from previous tests.)
CypressInstance.on('test:before:run', () => {
// leave the error overlay alone if it exists
if (document.body.querySelectorAll('vite-error-overlay').length) {
// make the error more readable by giving it more space
Cypress.action('cy:viewport:changed', { viewportWidth: 1000, viewportHeight: 500 })

return
}

// reset the viewport to default when in normal mode
Cypress.action('cy:viewport:changed', {
viewportWidth: Cypress.config('viewportWidth'),
viewportHeight: Cypress.config('viewportHeight'),
})
})

// Make usage of node test plugins possible
window.global = window
5 changes: 0 additions & 5 deletions npm/vite-dev-server/cypress/components/Foo.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions npm/vite-dev-server/cypress/components/react/Foo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import './foo.css'
import logo from './logo.png'

export const Foo: React.FC = () => {
return (<>
<div>Hello world!!!!</div>
<img src={logo} />
</>)
}
10 changes: 10 additions & 0 deletions npm/vite-dev-server/cypress/components/react/foo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
div{
color: white;
background: hotpink;
padding: 20px;
text-align: center;
}

img{
width:50%;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ describe('React', () => {
cy.get('div').contains('Hello world')
})

it('renders a react component #3', () => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})
it('renders a react component with a different viewport',
{ viewportWidth: 200, viewportHeight: 170 },
() => {
mount(<Foo />)
cy.get('div').contains('Hello world')
})

it('renders a react component #4', () => {
mount(<Foo />)
Expand Down
41 changes: 41 additions & 0 deletions npm/vite-dev-server/cypress/components/vue/Card/Card.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// In this test file we demo how to test a component with slots and a scoped slot.

// Usage is the same as Vue Test Utils, since slots and scopedSlots
// in the render options are directly passed through to the Utils mount().

/// <reference types="cypress" />
import { mount } from '@cypress/vue'

import Card from './Card.vue'

describe('Card', () => {
it('skipped slots', () => {
mount(Card)
cy.contains('Nothing used the Scoped content!').should('be.visible')
})

it('renders slots', () => {
mount(Card, {
slots: {
header: '<h1>HEADER</h1>',
footer: '<div>FOOTER</div>',
},
})

cy.contains('h1', 'HEADER')
cy.contains('div', 'FOOTER')
})

it('renders scopedSlots', () => {
mount(Card, {
slots: {
default: `<template #default="props">
<p>Yay! {{props.content}}</p>
</template>`,
},
})

cy.contains('Yay! Scoped content!').should('be.visible')
cy.contains('Nothing used the Scoped content!').should('not.exist')
})
})
24 changes: 24 additions & 0 deletions npm/vite-dev-server/cypress/components/vue/Card/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<div class="card">
<img src="./logo.png" />
<slot name="header" />
<slot :content="content">
<!-- Fallback content if no default slot is given -->
<p>Nothing used the {{ content }}</p>
</slot>
<slot name="footer" />
</div>
</template>

<script>
// example from https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/components/Card.vue
// For the sake of demoing scopedSlots, this Card component
// passes a simple string down to its default slot.
export default {
data() {
return {
content: "Scoped content!",
};
},
};
</script>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading