-
Notifications
You must be signed in to change notification settings - Fork 46
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
Major Jest Upgrades #1082
Merged
Merged
Major Jest Upgrades #1082
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c506a7c
refactor: update global Jest config to automatically skip over *.e2e.…
sghoweri fdea6e4
refactor: rename figure component test external data file
sghoweri 72be039
feat: update Jest to automatically transpile ES6 code (via Babel) to …
sghoweri 3eb8345
feat: upgrade Jest to automatically polyfill the testing environment …
sghoweri 8d910b0
feat: automatically boot up webpack dev server to remove the need to …
sghoweri aee3f0d
feat: add visual regression testing to Jest + add jest-dom as a new t…
sghoweri 843aeb0
feat: add simple image screenshot test reporting functionality to Jes…
sghoweri ea0bc17
refactor: remove old button component JS test
sghoweri 4b34184
feat: wire up button component to include VRT, web component tests, u…
sghoweri a56658b
refactor: move image test to proper folder
sghoweri cd1ce4e
feat: add new webpack dev server setup for quickly testing components…
sghoweri 983f4ad
chore: fix missing comma + update Jest NPM scripts without renaming t…
sghoweri 82a4673
fix: update dockerfile config + adjust Jest setup to ensure buildPrep…
sghoweri c9b7257
refactor: update monorepo Jest test to speed things up by 20 seconds!
sghoweri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,7 @@ module.exports = { | |
images: { | ||
sets: imageSets, | ||
}, | ||
prod: true, | ||
enableCache: true, | ||
verbosity: 1, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
/** | ||
* 1. Helps with our Web Component Preact renderer | ||
*/ | ||
'@babel/plugin-syntax-jsx' /* [1] */, | ||
[ | ||
'@babel/plugin-transform-react-jsx' /* [1] */, | ||
{ | ||
pragma: 'h', | ||
pragmaFrag: '"span"', | ||
throwIfNamespace: false, | ||
useBuiltIns: false, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { | ||
CustomElementRegistry, | ||
CustomEvent, | ||
Document, | ||
Event, | ||
Node, | ||
Text, | ||
HTMLElement, | ||
HTMLTemplateElement, | ||
HTMLUnknownElement, | ||
} = require('basichtml'); | ||
|
||
const raf = require('raf'); | ||
const NodeEnvironment = require('jest-environment-node'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const puppeteer = require('puppeteer'); | ||
const os = require('os'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); | ||
|
||
class BasicHTMLEnvironment extends NodeEnvironment { | ||
constructor(config) { | ||
super(config); | ||
|
||
const window = this.global; | ||
|
||
window.customElements = new CustomElementRegistry(); | ||
window.document = new Document(window.customElements); | ||
window.document = new Document(window.customElements); | ||
window.HTMLElement = HTMLElement; | ||
window.HTMLUnknownElement = HTMLUnknownElement; | ||
window.Node = Node; | ||
window.Text = Text; | ||
window.window = window; | ||
|
||
this.global.navigator = { | ||
userAgent: 'node.js', | ||
}; | ||
|
||
this.global.requestAnimationFrame = raf; | ||
// Ensure that the real global env has the document | ||
global.document = window.document; | ||
} | ||
|
||
async setup() { | ||
await super.setup(); | ||
// get the wsEndpoint | ||
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8'); | ||
if (!wsEndpoint) { | ||
throw new Error('wsEndpoint not found'); | ||
} | ||
|
||
// connect to puppeteer | ||
this.global.__BROWSER__ = await puppeteer.connect({ | ||
browserWSEndpoint: wsEndpoint, | ||
}); | ||
} | ||
|
||
runScript(script) { | ||
return super.runScript(script); | ||
} | ||
|
||
async teardown() { | ||
await super.teardown(); | ||
|
||
this.global.document = null; | ||
this.global.window = null; | ||
global.document = null; | ||
} | ||
} | ||
|
||
module.exports = BasicHTMLEnvironment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
const webpackTasks = require('@bolt/build-tools/tasks/webpack-tasks'); | ||
const createWebpackConfig = require('@bolt/build-tools/create-webpack-config'); | ||
const { buildPrep } = require('@bolt/build-tools/tasks/task-collections'); | ||
const imageTasks = require('@bolt/build-tools/tasks/image-tasks'); | ||
const { getConfig } = require('@bolt/build-tools/utils/config-store'); | ||
const { setup: setupDevServer } = require('jest-dev-server'); | ||
const puppeteer = require('puppeteer'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
|
||
module.exports = async function() { | ||
try { | ||
let config = await getConfig(); | ||
await buildPrep(); // Generate folders, manifest data, etc needed for Twig renderer | ||
await imageTasks.processImages(); // process image fixtures used by any tests | ||
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); | ||
|
||
// don't compile anything in Webpack except for the exported JSON data from Bolt's Design Tokens | ||
config.components.global = ['./packages/core/styles/index.scss']; | ||
config.components.individual = []; | ||
const { buildPrep } = require('./packages/build-tools/tasks/task-collections'); | ||
const imageTasks = require('./packages/build-tools/tasks/image-tasks'); | ||
const { getConfig } = require('./packages/build-tools/utils/config-store'); | ||
|
||
// Disabling Sourcemaps here technically isn't REQUIRED but this might help speed things along, especially on Travis | ||
config.sourceMaps = false; | ||
module.exports = async function globalSetup() { | ||
const config = await getConfig(); | ||
await buildPrep(); // Generate folders, manifest data, etc needed for Twig renderer | ||
await imageTasks.processImages(); // process image fixtures used by any tests | ||
|
||
const customWebpackConfig = await createWebpackConfig(config); | ||
await setupDevServer({ | ||
command: `node server/testing-server`, | ||
launchTimeout: 50000, | ||
port: 4444, | ||
}); | ||
|
||
await webpackTasks.compile(customWebpackConfig); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
const browser = await puppeteer.launch(); | ||
// store the browser instance so we can teardown it later | ||
// this global is only available in the teardown but not in TestEnvironments | ||
global.__BROWSER_GLOBAL__ = browser; | ||
|
||
global.navigator = { | ||
userAgent: 'node.js', | ||
}; | ||
|
||
// use the file system to expose the wsEndpoint for TestEnvironments | ||
mkdirp.sync(DIR); | ||
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const os = require('os'); | ||
const rimraf = require('rimraf'); | ||
const path = require('path'); | ||
|
||
const { teardown: teardownDevServer } = require('jest-dev-server'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); | ||
module.exports = async function() { | ||
// close the browser instance | ||
await global.__BROWSER_GLOBAL__.close(); | ||
|
||
await teardownDevServer(); | ||
|
||
// clean-up the wsEndpoint file | ||
rimraf.sync(DIR); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const { toMatchImageSnapshot } = require('jest-image-snapshot'); | ||
expect.extend({ toMatchImageSnapshot }); | ||
|
||
import 'jest-dom/extend-expect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+7.45 KB
...pshots__/button-js-button-default-bolt-button-w-o-shadow-dom-renders-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...shots__/button-js-button-default-bolt-button-with-shadow-dom-renders-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This testFilesToIgnore don't cover
figure-data.js
this looking files with.data.js
andbolt-figure
component usefigure-data.js
. Please correct me if i'm wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad i saw that you change
figure-data.js
tofigure.data.js
:)