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

Major Jest Upgrades #1082

Merged
merged 14 commits into from
Feb 20, 2019
Merged
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
3 changes: 3 additions & 0 deletions .boltrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ module.exports = {
images: {
sets: imageSets,
},
prod: true,
enableCache: true,
verbosity: 1,
};
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EXPOSE 3123
COPY docs-site /app/docs-site
COPY packages /app/packages
COPY www /app/www
COPY server/package.json .
COPY server/package.json /app/server/package.json
COPY .boltrc.js .
COPY yarn.lock .
COPY server /app/server
Expand All @@ -17,6 +17,6 @@ RUN cd packages/twig-renderer && yarn run setup
RUN cd packages/drupal-twig-extensions && yarn run setup
RUN cd packages/core-php && yarn run setup

RUN yarn install --production
RUN yarn --cwd server --ignore-optional --ignore-platform --ignore-scripts --ignore-engines --skip-integrity-check --production --modules-folder node_modules

CMD node server/index.js
27 changes: 27 additions & 0 deletions babel.config.js
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,
},
],
],
};
73 changes: 73 additions & 0 deletions jest-environment-puppeteer-basichtml.js
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;
51 changes: 31 additions & 20 deletions jest-global-setup.js
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());
};
16 changes: 16 additions & 0 deletions jest-global-teardown.js
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);
};
4 changes: 4 additions & 0 deletions jest-setup-files-after-env.js
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';
22 changes: 19 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// https://facebook.github.io/jest/docs/en/configuration.html
const globby = require('globby');
const testFilesToIgnore = globby.sync([
'./packages/components/**/*/__tests__/*.e2e.js',
'./packages/components/**/*/__tests__/*.data.js'
Copy link
Collaborator

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 and bolt-figure component use figure-data.js. Please correct me if i'm wrong.

Copy link
Collaborator

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.jsto figure.data.js :)

]);

module.exports = {
testPathIgnorePatterns: [
'sandbox',
Expand All @@ -9,12 +15,22 @@ module.exports = {
'packages/build-tools/plugins/sass-export-data/tests',
'packages/components/bolt-button/__tests__/button-wc.test.js',
'packages/patternlab-node',
'packages/components/bolt-video/__tests__/bolt-video.e2e.js',
'packages/components/bolt-figure/__tests__/figure-data.js',
...testFilesToIgnore,
],
testEnvironment: './jest-environment-puppeteer-basichtml.js',
transform: {
'^.+\\.js?$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!(lit-html|@bolt|@open-wc)/)', // add any additional packages in node_modules that need to be transpiled for Jest
'packages/(?!(components|core)/)', // add any additional packages in node_modules that need to be transpiled for Jest
'./scripts/monorepo.test.js',
],
testEnvironment: 'node',
globalSetup: './jest-global-setup.js',
globalTeardown: './jest-global-teardown.js',
setupFilesAfterEnv: ['./jest-setup-files-after-env.js'],
snapshotSerializers: ['jest-serializer-html'],
reporters: ['default', '<rootDir>/scripts/report-jest-screenshots.js'],
// Notify not working correctly; we want to only get a notification when tests fail, and then get ONE success notificaiton after it passes
// notify: true,
// notifyMode: 'failure-success',
Expand Down
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"lint:js": "eslint --max-warnings 0 'packages/**/*.js' 'docs-site/**/*.js'",
"lint:scss": "stylelint 'packages/**/*.scss' 'docs-site/**/*.scss' --config .stylelintrc",
"test": "npm-run-all --parallel test:js test:php test:monorepo",
"test:js": "NODE_ENV='test' jest",
"jest:update": "NODE_ENV='test' jest -u",
"test:js": "NODE_ENV='test' jest --bail --colors",
"test:js:update": "yarn run test:js -u",
"test:monorepo": "node scripts/monorepo-tests.js",
"test:php": "npx lerna exec --scope @bolt/core-php -- composer run test",
"test:e2e:quick-live": " NOW_URL=https://boltdesignsystem.com ./node_modules/.bin/nightwatch --config nightwatch.js --env local",
Expand Down Expand Up @@ -72,6 +72,7 @@
]
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@commitlint/cli": "^7.4.0",
"@commitlint/config-conventional": "^7.3.1",
"@instructure/cz-lerna-changelog": "^5.40.0",
Expand All @@ -84,8 +85,18 @@
"semantic-release": "^15.13.3"
},
"dependencies": {
"babel-jest": "^24.1.0",
"@open-wc/testing-helpers": "^0.7.12",
"basichtml": "^0.21.1",
"jest-dev-server": "^3.9.0",
"jest-dom": "^3.0.1",
"jest-environment-node": "^24.0.0",
"jest-image-snapshot": "^2.8.0",
"puppeteer": "^1.12.2",
"mkdirp": "^0.5.1",
"@zeit/fetch-retry": "^3.0.0",
"ci-utils": "^0.5.0",
"raf": "^3.4.1",
"express": "^4.16.4",
"jest-serializer-html": "^6.0.0",
"jest": "^24.0.0",
Expand All @@ -101,7 +112,8 @@
"shelljs": "^0.8.3",
"sleep-promise": "^8.0.1",
"url-exists": "^1.0.3",
"yaml-lint": "^1.2.4"
"yaml-lint": "^1.2.4",
"now-storage": "^1.3.0"
},
"workspaces": {
"packages": [
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions packages/components/bolt-button/__tests__/__snapshots__/button.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,106 @@ exports[`button Button with outer classes via Drupal Attributes 1`] = `

`;

exports[`button Default <bolt-button> w/o Shadow DOM renders 2`] = `
<bolt-button
style=""
>
<!---->



<button
class="c-bolt-button c-bolt-button--center c-bolt-button--primary c-bolt-button--medium c-bolt-button--border-radius-regular"
style=""
>
<!---->
<!---->


<span
class="c-bolt-button__icon is-empty"
style=""
>
<!---->


<slot
name="before"
style=""
>


</slot>
<!---->
</span>


<!---->


<span
class="c-bolt-button__item"
style=""
>
<!---->
<!---->
<!---->
Hello World!
<!---->
<!---->
<!---->
</span>


<!---->


<span
class="c-bolt-button__icon is-empty"
style=""
>
<!---->


<slot
name="after"
style=""
>


</slot>
<!---->
</span>


<!---->
<!---->
</button>



<!---->
</bolt-button>
`;

exports[`button Default <bolt-button> with Shadow DOM renders 2`] = `
<style
style=""
>

bolt-button{display:inline-block;display:inline-flex}.c-bolt-button{padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;font-family:var(--bolt-font-family-body);-webkit-appearance:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;font-weight:600;box-shadow:0 1px 4px 1px rgba(6,10,36,.1),0 5px 10px 0 rgba(6,10,36,.08);transition:.3s cubic-bezier(.25,.8,.25,1);display:inline-block;display:inline-flex;flex-direction:row;flex-grow:1;align-items:center;position:relative;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);text-decoration:none;vertical-align:middle;cursor:pointer;border-radius:3px;border-width:1px;border-style:solid}.js-fonts-loaded .c-bolt-button{font-family:"Open Sans","Helvetica Neue",sans-serif;font-family:var(--bolt-font-family-body)}.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]).is-hover,.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]):hover{-webkit-transform:translateY(-2px);transform:translateY(-2px);box-shadow:0 1px 8px 1px rgba(6,10,36,.18),0 5px 10px 1px rgba(6,10,36,.15),0 15px 30px 0 rgba(6,10,36,.16)}.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]).is-hover:before,.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]):hover:before{opacity:1}.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]).is-active,.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]):active{-webkit-transform:translate3d(0,1px,0);transform:translate3d(0,1px,0)}.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]).is-active:before,.c-bolt-button:not(.c-bolt-button--disabled):not(.c-bolt-button--text):not([disabled]):active:before{opacity:0}.c-bolt-button:before{content:'';display:block;opacity:.2;position:absolute;top:0;left:0;z-index:-5;width:100%;height:100%;pointer-events:none;border-radius:3px;-webkit-transform:translateY(-2px);transform:translateY(-2px)}.c-bolt-button--primary,.c-bolt-button--primary:visited{color:rgba(var(--bolt-theme-text-on-primary), 1);border-color:rgba(var(--bolt-theme-primary), 1);background-color:rgba(var(--bolt-theme-primary), 1)}.c-bolt-button--primary.is-hover,.c-bolt-button--primary:hover{color:rgba(var(--bolt-theme-text-on-primary-lighten-15), 1);border-color:rgba(var(--bolt-theme-primary-lighten-15), 1);background-color:rgba(var(--bolt-theme-primary-lighten-15), 1)}.c-bolt-button--primary.is-focus,.c-bolt-button--primary:focus{color:rgba(var(--bolt-theme-text-on-primary-darken-15), 1);border-color:rgba(var(--bolt-theme-primary-darken-15), 1);background-color:rgba(var(--bolt-theme-primary-darken-15), 1)}.c-bolt-button--primary.is-active,.c-bolt-button--primary:active{color:rgba(var(--bolt-theme-text-on-primary-darken-25), 1);border-color:rgba(var(--bolt-theme-primary-darken-25), 1);background-color:rgba(var(--bolt-theme-primary-darken-25), 1)}.c-bolt-button--secondary,.c-bolt-button--secondary:visited{color:rgba(var(--bolt-theme-text-on-secondary), 1);border-color:rgba(var(--bolt-theme-secondary), 1);background-color:rgba(var(--bolt-theme-secondary), 1)}.c-bolt-button--secondary.is-hover,.c-bolt-button--secondary:hover{color:rgba(var(--bolt-theme-text-on-secondary-lighten-5), 1);border-color:rgba(var(--bolt-theme-secondary-lighten-5), 1);background-color:rgba(var(--bolt-theme-secondary-lighten-5), 1)}.c-bolt-button--secondary.is-focus,.c-bolt-button--secondary:focus{color:rgba(var(--bolt-theme-text-on-secondary-darken-3), 1);border-color:rgba(var(--bolt-theme-secondary-darken-3), 1);background-color:rgba(var(--bolt-theme-secondary-darken-3), 1)}.c-bolt-button--secondary.is-active,.c-bolt-button--secondary:active{color:rgba(var(--bolt-theme-text-on-secondary-darken-10), 1);border-color:rgba(var(--bolt-theme-secondary-darken-10), 1);background-color:rgba(var(--bolt-theme-secondary-darken-10), 1)}.c-bolt-button--text{text-decoration:none;border-color:transparent;background-color:transparent;opacity:1;color:rgba(var(--bolt-theme-headline-link), 1)}.c-bolt-button--text,.c-bolt-button--text:before{border-radius:0;box-shadow:none}.c-bolt-button--text:visited{opacity:1}.c-bolt-button--text:hover:not([disabled]){opacity:.8}.c-bolt-button--text:active,.c-bolt-button--text:focus:active{opacity:.6}.c-bolt-button--disabled,.c-bolt-button[disabled]{cursor:not-allowed}.c-bolt-button--disabled,.c-bolt-button--disabled:active,.c-bolt-button--disabled:hover,.c-bolt-button--disabled:visited,.c-bolt-button[disabled],.c-bolt-button[disabled]:active,.c-bolt-button[disabled]:hover,.c-bolt-button[disabled]:visited{color:rgba(var(--bolt-theme-text-disabled), 1);border-color:rgba(var(--bolt-theme-disabled), 1);background-color:rgba(var(--bolt-theme-disabled), 1)}.c-bolt-button--disabled:active:before,.c-bolt-button--disabled:before,.c-bolt-button--disabled:hover:before,.c-bolt-button[disabled]:active:before,.c-bolt-button[disabled]:before,.c-bolt-button[disabled]:hover:before{opacity:1}.c-bolt-button--disabled,.c-bolt-button--disabled:active,.c-bolt-button--disabled:hover,.c-bolt-button[disabled],.c-bolt-button[disabled]:active,.c-bolt-button[disabled]:hover{-webkit-transform:none;transform:none}.c-bolt-button--uppercase{text-transform:uppercase}.c-bolt-button--lowercase{text-transform:lowercase}.c-bolt-button--capitalize{text-transform:capitalize}.c-bolt-button--medium{padding:.825rem 2rem;font-size:.8rem;line-height:1.45}.c-bolt-button--medium.c-bolt-button--icon-only{padding:2rem}.c-bolt-button--xxsmall{padding:.103rem .25rem;font-size:.8rem;line-height:1.45}.c-bolt-button--xxsmall.c-bolt-button--icon-only{padding:.25rem}.c-bolt-button--xsmall{padding:.206rem .5rem;font-size:.8rem;line-height:1.45}.c-bolt-button--xsmall.c-bolt-button--icon-only{padding:.5rem}.c-bolt-button--small{padding:.412rem 1rem;font-size:.8rem;line-height:1.45}.c-bolt-button--small.c-bolt-button--icon-only{padding:1rem}.c-bolt-button--large{padding:.825rem 2rem;font-size:1rem;line-height:1.65}.c-bolt-button--large.c-bolt-button--icon-only{padding:2rem}.c-bolt-button--xlarge{padding:1.65rem 4rem;font-size:1.111rem;line-height:1.45}.c-bolt-button--xlarge.c-bolt-button--icon-only{padding:4rem}.c-bolt-button--full,bolt-button[width=full]{width:100%}:host([width=full]){width:100%}@media (min-width:37.5em){.c-bolt-button--full\\@small,bolt-button[width='full@small']{width:100%}:host([width='full@small']){width:100%}}.c-bolt-button--border-radius-regular,.c-bolt-button--border-radius-regular:before{border-radius:3px}.c-bolt-button--border-radius-full,.c-bolt-button--border-radius-full:before{border-radius:50em}.c-bolt-button--center{justify-content:center;text-align:center}.c-bolt-button--start{justify-content:flex-start;text-align:left;text-align:start}.c-bolt-button--end{justify-content:flex-end;text-align:right;text-align:end}.c-bolt-button__item+.c-bolt-button__icon:not(.is-empty){margin-left:.25rem}.c-bolt-button--icon-only .c-bolt-button__item+.c-bolt-button__icon:not(.is-empty){margin-left:0}.c-bolt-button__icon:not(.is-empty)+.c-bolt-button__item{margin-left:.5rem}.c-bolt-button--icon-only .c-bolt-button__icon:not(.is-empty)+.c-bolt-button__item{margin-left:0}.c-bolt-button__icon{display:inline-block;display:inline-flex;align-self:center;line-height:1;text-align:center;vertical-align:middle;transition:-webkit-transform 150ms ease-in-out;transition:transform 150ms ease-in-out;transition:transform 150ms ease-in-out, -webkit-transform 150ms ease-in-out} .u-bolt-visuallyhidden{position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;margin:-1px!important;padding:0!important;border:0!important;clip:rect(0 0 0 0)!important;-webkit-clip-path:inset(50%)!important;clip-path:inset(50%)!important;white-space:nowrap!important}

</style>
`;

exports[`button Default <bolt-button> with Shadow DOM renders 3`] = `
<bolt-button
style=""
>
Button Test -- Outer HTML
</bolt-button>
`;

exports[`button basic button 1`] = `

<bolt-button align="center"
Expand Down
Loading