Skip to content

Commit

Permalink
fix: make component testing windows compatible (#15889)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barthélémy Ledoux authored Apr 10, 2021
1 parent a5bb2e0 commit 602c762
Show file tree
Hide file tree
Showing 22 changed files with 5,497 additions and 136 deletions.
25 changes: 25 additions & 0 deletions npm/lazy-compile-webpack-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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*

/demo
6 changes: 6 additions & 0 deletions npm/lazy-compile-webpack-plugin/.releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
...require('../../.releaserc.base'),
branches: [
{ name: 'master', channel: 'latest' },
],
}
21 changes: 21 additions & 0 deletions npm/lazy-compile-webpack-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 X.L

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
73 changes: 73 additions & 0 deletions npm/lazy-compile-webpack-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Lazy Compile Webpack Plugin</h1>
<p>Plugin that saves a tremendous amount of time.</p>
</div>

## Fork from https://github.com/liximomo/lazy-compile-webpack-plugin/

To enable windows compatibility we forked this repo and fixed the windows issue.

## Why

Starting the development server is taking you a long time when the codebase is large. You have tried dynamic imports, it only does a load-on-demand, the whole project was still been compiled. We don't want to wait a couple of minutes for a simple modification. People don't waste time for the things they have never used!

## Install

```sh
# npm
npm i -D lazy-compile-webpack-plugin

# yarn
yarn add -D lazy-compile-webpack-plugin
```

## Usage

```js
const LazyCompilePlugin = require('lazy-compile-webpack-plugin');

module.exports = {
entry: 'index.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js',
},
plugins: [new LazyCompilePlugin()],
};
```

## Options

| Name | Type | Default | Description |
| :-----------------------------------------------: | :---------------------: | :---------: | :------------------------------------------------------- |
| **[`refreshAfterCompile`](#refreshAfterCompile)** | `boolean` | `false` | Enable/Disable _page refresh_ when compilation is finish |
| **[`ignores`](#ignores)** | `RegExp[] \| Function[]` | `undefined` | Request to be ignored from lazy compiler |

### `refreshAfterCompile`

Type: `boolean`
Default: `false`

Set `false` for a seamless dev experience.

### `ignores`

Type: `RegExp[] | ((request: string, wpModule: object) => boolean)`
Default: `undefined`

Request to be ignored from lazy compiler, `html-webpack-plugin` is always ignored.

Specifically, an Angular app should enable this option like following:

```js
new LazyCompileWebpackPlugin({
ignores: [
/\b(html|raw|to-string)-loader\b/,
/\bexports-loader[^?]*\?exports\.toString\(\)/
],
});
```
1 change: 1 addition & 0 deletions npm/lazy-compile-webpack-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/plugin')
71 changes: 71 additions & 0 deletions npm/lazy-compile-webpack-plugin/lib/loaders/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-env browser */
let isBrowser = typeof window !== 'undefined'

let GLOBAL_ANIMATION_KEY = '__lazyCompileWebpackPlugin'

function noop () {}

// modified from https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis
let figures = [
'🕐',
'🕑',
'🕒',
'🕓',
'🕔',
'🕕',
'🕖',
'🕗',
'🕘',
'🕙',
'🕚',
'🕛',
]

function startAnimation () {
if (!isBrowser) return noop

if (window[GLOBAL_ANIMATION_KEY]) return noop

window[GLOBAL_ANIMATION_KEY] = true

let originTitle = document.title

let loopHandle

function animatioLoop () {
loopHandle = setTimeout(animatioLoop, 50)
document.title =
`Compiling ${ figures[Math.floor((Date.now() / 100) % figures.length)]}`
}
animatioLoop()

return () => {
window[GLOBAL_ANIMATION_KEY] = false
clearTimeout(loopHandle)
document.title = originTitle
}
}

function compile (endpoints, activationUrl) {
let ready
let prom = new Promise((resolve) => {
ready = resolve
if (!isBrowser) return

endpoints.forEach(function (endpoint) {
let img = new Image()

img.src = activationUrl.replace('{host}', endpoint)
})
})

prom.ready = ready

return prom
}

module.exports = {
isBrowser,
startAnimation,
compile,
}
20 changes: 20 additions & 0 deletions npm/lazy-compile-webpack-plugin/lib/loaders/entry-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require('path')
const loaderUtils = require('loader-utils')
const apiPath = path.join(__dirname, 'api.js')

module.exports = function () {
const { activationUrl, ips } = loaderUtils.getOptions(this) || {}

return `
// @activationUrl ${activationUrl}
var api = require(${loaderUtils.stringifyRequest(this, `!!${apiPath}`)});
api.compile(${JSON.stringify(ips)}, '${activationUrl}');
if (api.isBrowser) {
setTimeout(function () {
window.location.reload()
}, 0)
}
`.trim()
}
59 changes: 59 additions & 0 deletions npm/lazy-compile-webpack-plugin/lib/loaders/module-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const path = require('path')
const loaderUtils = require('loader-utils')
const apiPath = path.join(__dirname, 'api.js')

module.exports = function () {
const { activationUrl, ips, hmr } = loaderUtils.getOptions(this) || {}
const hmrCode = `
if (module.hot) {
module.hot.dispose(function() {
stopAnimation();
// wait for the module to install
setTimeout(() => {
// depressed warning: "unexpected require from disposed module"
module.hot.active = true;
compilation.ready(__webpack_require__(module.id));
module.hot.active = false;
}, 0);
});
module.hot.accept(function() {
// error handle
});
}
`.trim()

const refreshCode = `
window.onbeforeunload = function() {
stopAnimation();
}
`.trim()

return `
//############################ NOTICE ############################//
// //
// This is a placeholder module generated by //
// lazy-compile-webpack-plugin. //
// https://github.com/liximomo/lazy-compile-webpack-plugin //
// //
// The real content is in the corresponding hot-update file. //
// You won't see this after the page refresh. //
// //
//################################################################//
// @activationUrl ${activationUrl}
// modified from https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis
var api = require(${loaderUtils.stringifyRequest(this, `!!${apiPath}`)});
var stopAnimation = api.startAnimation();
var compilation = api.compile(${JSON.stringify(ips)}, '${activationUrl}');
${hmr ? hmrCode : refreshCode}
module.exports = {
then(resolve) {
resolve(compilation)
}
}
`.trim()
}
Loading

4 comments on commit 602c762

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 602c762 Apr 10, 2021

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/circle-develop-602c762cfd707ae497273ac38206d7f9d8545439/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 602c762 Apr 10, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/appveyor-develop-602c762cfd707ae497273ac38206d7f9d8545439/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 602c762 Apr 10, 2021

Choose a reason for hiding this comment

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

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/appveyor-develop-602c762cfd707ae497273ac38206d7f9d8545439/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 602c762 Apr 10, 2021

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.0.2/circle-develop-602c762cfd707ae497273ac38206d7f9d8545439/cypress.tgz

Please sign in to comment.