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

test: Migrate jest to use projects feature #322

Merged
merged 26 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
79acc55
test: move to proper jest project structure
pmdartus May 18, 2018
e71b82a
test: remove only
pmdartus May 18, 2018
b2cf0d9
test: add setup script to clean up the registry after each test
pmdartus May 18, 2018
704ee1d
wip: fix more tests
pmdartus May 19, 2018
bd1ec47
wip: fix more warnings
pmdartus May 19, 2018
a46695a
wip: fix more tests
pmdartus May 19, 2018
c9f2af7
test: refactor test config to be at the monorepo root
pmdartus May 20, 2018
803109b
style: make jest.config.consistent
pmdartus May 21, 2018
7e7d3ac
fix: remove unused import
pmdartus May 21, 2018
e046412
test: move to proper jest project structure
pmdartus May 18, 2018
1a6d11a
test: remove only
pmdartus May 18, 2018
b0d9377
test: add setup script to clean up the registry after each test
pmdartus May 18, 2018
52da269
wip: fix more tests
pmdartus May 19, 2018
2839cdc
wip: fix more warnings
pmdartus May 19, 2018
b222796
wip: fix more tests
pmdartus May 19, 2018
385e839
test: refactor test config to be at the monorepo root
pmdartus May 20, 2018
32c340e
style: make jest.config.consistent
pmdartus May 21, 2018
bfe25cf
fix: remove unused import
pmdartus May 21, 2018
064ca91
fix: remove unused deps in engine unit tests
pmdartus May 29, 2018
3a1b277
Merge branch 'pmdartus/jest-restructure' of github.com:salesforce/lwc…
pmdartus May 29, 2018
ba09e2a
wip: remove internal engine registry
pmdartus May 30, 2018
d0d3242
style: fix engine linting
pmdartus May 30, 2018
a9921a2
Merge branch 'master' into pmdartus/jest-restructure
pmdartus May 30, 2018
56d1a1b
fix: make sure to resolve circular deps in createElement
pmdartus May 31, 2018
7c31f72
style: fix linting errors
pmdartus May 31, 2018
c90ef6c
style: update code based on feedback
pmdartus May 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clean": "lerna run clean && lerna clean --yes && rm -rf node_modules",
"lint": "tslint -p tsconfig.json && npm run types",
"types": "tsc --noEmit",
"test": "jest",
"test": "jest --config ./scripts/jest/root.config.js",
"test:integration": "yarn run build && lerna exec --scope lwc-integration -- yarn sauce",
"test:performance": "lerna exec --scope benchmark -- best --runner remote",
"build": "lerna run build --ignore benchmark --ignore lwc-integration",
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-plugin-transform-lwc-class/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const BASE_CONFIG = require('../../scripts/jest/base.config');

module.exports = {
...BASE_CONFIG,
displayName: 'babel-plugin-transform-lwc-class',
};
6 changes: 6 additions & 0 deletions packages/lwc-compiler/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const BASE_CONFIG = require('../../scripts/jest/base.config');

module.exports = {
...BASE_CONFIG,
displayName: 'lwc-compiler',
};
7 changes: 7 additions & 0 deletions packages/lwc-engine/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const BASE_CONFIG = require('../../scripts/jest/base.config');

module.exports = {
...BASE_CONFIG,
displayName: 'lwc-engine',
setupTestFrameworkScriptFile: '<rootDir>/scripts/jest/setup.ts',
};
6 changes: 3 additions & 3 deletions packages/lwc-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"clean": "rm -rf dist",
"build": "concurrently \"yarn build:es-and-cjs\" \"yarn build:umd:prod\" \"yarn build:umd:dev\"",
"test": "DIR=`pwd` && cd ../../ && yarn test $DIR",
"build:umd:dev": "rollup -c scripts/rollup.config.umd.dev.js",
"build:umd:prod": "rollup -c scripts/rollup.config.umd.prod.js",
"build:es-and-cjs": "rollup -c scripts/rollup.config.es-and-cjs.js"
"build:umd:dev": "rollup -c scripts/rollup/rollup.config.umd.dev.js",
"build:umd:prod": "rollup -c scripts/rollup/rollup.config.umd.prod.js",
"build:es-and-cjs": "rollup -c scripts/rollup/rollup.config.es-and-cjs.js"
},
"devDependencies": {
"concurrently": "^3.5.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/lwc-engine/scripts/jest/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { flushComponentRegistry } from '../../src/framework/def';

// Clean-up after each test the engine component registry. This avoid having the
// engine warning that multiple component class are registered with the same name.
afterEach(() => {
flushComponentRegistry();
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const typescript = require('rollup-plugin-typescript');
const nodeResolve = require('rollup-plugin-node-resolve');

const { generateTargetName, ignoreCircularDependencies } = require('./engine.rollup.config.util');
const { version } = require('../package.json');
const { version } = require('../../package.json');

const entry = path.resolve(__dirname, '../src/framework/main.ts');
const commonJSDirectory = path.resolve(__dirname, '../dist/commonjs');
const modulesDirectory = path.resolve(__dirname, '../dist/modules');
const entry = path.resolve(__dirname, '../../src/framework/main.ts');
const commonJSDirectory = path.resolve(__dirname, '../../dist/commonjs');
const modulesDirectory = path.resolve(__dirname, '../../dist/modules');

const banner = (`/* proxy-compat-disable */`);
const footer = `/** version: ${version} */`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const replace = require('rollup-plugin-replace');
const typescript = require('rollup-plugin-typescript');
const nodeResolve = require('rollup-plugin-node-resolve');

const { version } = require('../package.json');
const { version } = require('../../package.json');
const { generateTargetName, ignoreCircularDependencies } = require('./engine.rollup.config.util');

const input = path.resolve(__dirname, '../src/framework/main.ts');
const outputDir = path.resolve(__dirname, '../dist/umd');
const input = path.resolve(__dirname, '../../src/framework/main.ts');
const outputDir = path.resolve(__dirname, '../../dist/umd');

const banner = (`/* proxy-compat-disable */`);
const footer = `/** version: ${version} */`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const typescript = require('typescript');
const rollupTypescriptPlugin = require('rollup-plugin-typescript');
const nodeResolve = require('rollup-plugin-node-resolve');
const babelMinify = require('babel-minify');
const { version } = require('../package.json');
const { version } = require('../../package.json');
const { generateTargetName, ignoreCircularDependencies } = require('./engine.rollup.config.util');

const entry = path.resolve(__dirname, '../src/framework/main.ts');
const outputDir = path.resolve(__dirname, '../dist/umd');
const entry = path.resolve(__dirname, '../../src/framework/main.ts');
const outputDir = path.resolve(__dirname, '../../dist/umd');
const banner = (`/* proxy-compat-disable */`);
const footer = `/** version: ${version} */`;

Expand Down
12 changes: 6 additions & 6 deletions packages/lwc-engine/src/framework/__tests__/class-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('foo');
});

Expand All @@ -33,7 +33,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('foo');
});

Expand All @@ -53,7 +53,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('bar baz foo');
});

Expand All @@ -73,7 +73,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('');
});

Expand All @@ -93,7 +93,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('foo');
});

Expand All @@ -113,7 +113,7 @@ describe('class-list', () => {
}
const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const childElm = elm[ViewModelReflection].component.root.querySelector('x-child');
const childElm = elm[ViewModelReflection].component.template.querySelector('x-child');
expect(childElm.className).toBe('bar foo');
});

Expand Down
6 changes: 3 additions & 3 deletions packages/lwc-engine/src/framework/__tests__/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('component', function() {
const elm = createElement('x-foo', { is: Parent });
document.body.appendChild(elm);
expect(elm.lunch).toBe('salad');
expect(elm[ViewModelReflection].component.root.querySelector('x-component').breakfast).toBe('pancakes');
expect(elm[ViewModelReflection].component.template.querySelector('x-component').breakfast).toBe('pancakes');
});

it('should allow calling public getters when element is accessed by querySelector', function() {
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('component', function() {
}
});
document.body.appendChild(elm);
expect(elm[ViewModelReflection].component.root.querySelector('section').style.cssText).toBe('color: red;');
expect(elm[ViewModelReflection].component.template.querySelector('section').style.cssText).toBe('color: red;');
expect(calledCSSText).toBe(true);
});

Expand Down Expand Up @@ -455,7 +455,7 @@ describe('component', function() {

const elm = createElement('x-foo', { is: MyComponent });
document.body.appendChild(elm);
const section = elm[ViewModelReflection].component.root.querySelector('section');
const section = elm[ViewModelReflection].component.template.querySelector('section');
section.style.removeProperty = function() {
called = true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('error boundary component', () => {
return html;
}
}
const boundaryHostElm = createElement('x-boundary', {is: BoundryHost});
const boundaryHostElm = createElement('x-parent', {is: BoundryHost});
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you changing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it not to conflict with line 70, one of the children of x-boundary is also a x-boundary but with a different class. The engine logs a warning because of this.


document.body.appendChild(boundaryHostElm);
expect(querySelectorAll.call(boundaryHostElm, 'x-boundary-sibling').length).toBe(1);
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('error boundary component', () => {
return html;
}
}
const boundaryHostElm = createElement('x-boundary', {is: BoundryHost});
const boundaryHostElm = createElement('x-parent', {is: BoundryHost});
document.body.appendChild(boundaryHostElm);

expect(querySelectorAll.call(boundaryHostElm, 'x-boundary-sibling').length).toBe(1);
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('error boundary component', () => {
return html;
}
}
const boundaryHostElm = createElement('x-boundary', {is: BoundryHost});
const boundaryHostElm = createElement('x-parent', {is: BoundryHost});
document.body.appendChild(boundaryHostElm);

expect(querySelectorAll.call(boundaryHostElm, 'x-boundary-sibling').length).toBe(1);
Expand Down Expand Up @@ -530,7 +530,7 @@ describe('error boundary component', () => {
return html;
}
}
const boundaryHostElm = createElement('x-boundary', {is: BoundryHost});
const boundaryHostElm = createElement('x-parent', {is: BoundryHost});
document.body.appendChild(boundaryHostElm);

expect(querySelectorAll.call(boundaryHostElm, 'x-boundary-sibling').length).toBe(1);
Expand Down
10 changes: 5 additions & 5 deletions packages/lwc-engine/src/framework/__tests__/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Events on Custom Elements', () => {
elm = createElement('x-foo', { is: Foo });
elm.addEventListener('click', clicked2);
document.body.appendChild(elm);
cmp.root.querySelector('div').click();
cmp.template.querySelector('div').click();
expect(result).toEqual([1, 2]);
});

Expand All @@ -120,7 +120,7 @@ describe('Events on Custom Elements', () => {
}
elm = createElement('x-foo', { is: Foo });
document.body.appendChild(elm);
cmp.root.querySelector('div').click();
cmp.template.querySelector('div').click();
expect(result).toEqual([1]);
});

Expand All @@ -145,7 +145,7 @@ describe('Events on Custom Elements', () => {
elm = createElement('x-foo', { is: Foo });
elm.addEventListener('click', clicked2);
document.body.appendChild(elm);
cmp.root.querySelector('div').click();
cmp.template.querySelector('div').click();
expect(result).toEqual([1]);
});

Expand All @@ -168,7 +168,7 @@ describe('Events on Custom Elements', () => {
}
elm = createElement('x-foo', { is: Foo });
document.body.appendChild(elm);
cmp.root.querySelector('div').dispatchEvent(new CustomEvent('test', { bubbles: true })); // intentionally without composed: true to see if the root captures can that
cmp.template.querySelector('div').dispatchEvent(new CustomEvent('test', { bubbles: true })); // intentionally without composed: true to see if the root captures can that
expect(result).toHaveLength(1);
});

Expand All @@ -191,7 +191,7 @@ describe('Events on Custom Elements', () => {
}
elm = createElement('x-foo', { is: Foo });
document.body.appendChild(elm);
cmp.root.querySelector('div').click();
cmp.template.querySelector('div').click();
expect(result).toHaveLength(2);
expect(result[0]).toBe(undefined); // context must be the component
expect(result[1]).toBeInstanceOf(Event);
Expand Down
33 changes: 17 additions & 16 deletions packages/lwc-engine/src/framework/__tests__/html-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import { VNode } from "../../3rdparty/snabbdom/types";
import { Component } from "../component";
import { unwrap } from "../main";
import { querySelector } from "../dom";
import { callbackify } from "util";
Copy link
Contributor

Choose a reason for hiding this comment

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

hate when we have util package, it messes up with our regular autoimports if they match the same exported name :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. I will remove this, it was inserted by VSCode!


describe('html-element', () => {
describe('#setAttributeNS()', () => {
it('should set attribute on host element when element is nested in template', () => {
class MyComponent extends Element {
class Child extends Element {
setFoo() {
this.setAttributeNS('x', 'foo', 'bar');
}
}
MyComponent.publicMethods = ['setFoo'];
Child.publicMethods = ['setFoo'];

class Parent extends Element {
render() {
return ($api) => {
return [$api.c('should-set-attribute-on-host-element-when-element-is-nested-in-template-child', MyComponent, {})]
return [$api.c('x-child', Child, {})]
}
}
}
const element = createElement('should-set-attribute-on-host-element-when-element-is-nested-in-template', { is: Parent });
document.body.appendChild(element);
const child = querySelector.call(element, 'should-set-attribute-on-host-element-when-element-is-nested-in-template-child');
const child = querySelector.call(element, 'x-child');
child.setFoo();
expect(child.hasAttributeNS('x', 'foo')).toBe(true);
expect(child.getAttributeNS('x', 'foo')).toBe('bar');
Expand Down Expand Up @@ -61,23 +62,23 @@ describe('html-element', () => {

describe('#setAttribute()', () => {
it('should set attribute on host element when element is nested in template', () => {
class MyComponent extends Element {
class Child extends Element {
setFoo() {
this.setAttribute('foo', 'bar');
}
}
MyComponent.publicMethods = ['setFoo'];
Child.publicMethods = ['setFoo'];

class Parent extends Element {
render() {
return ($api) => {
return [$api.c('should-set-attribute-on-host-element-when-element-is-nested-in-template-child', MyComponent, {})]
return [$api.c('x-child', Child, {})]
}
}
}
const element = createElement('should-set-attribute-on-host-element-when-element-is-nested-in-template', { is: Parent });
document.body.appendChild(element);
const child = querySelector.call(element, 'should-set-attribute-on-host-element-when-element-is-nested-in-template-child');
const child = querySelector.call(element, 'x-child');
child.setFoo();
expect(child.hasAttribute('foo')).toBe(true);
expect(child.getAttribute('foo')).toBe('bar');
Expand Down Expand Up @@ -111,17 +112,17 @@ describe('html-element', () => {

describe('#removeAttributeNS()', () => {
it('should remove namespaced attribute on host element when element is nested in template', () => {
class MyComponent extends Element {
class Child extends Element {
removeTitle() {
this.removeAttributeNS('x', 'title');
}
}
MyComponent.publicMethods = ['removeTitle'];
Child.publicMethods = ['removeTitle'];

class Parent extends Element {
render() {
return ($api) => {
return [$api.c('remove-namespaced-attribute-on-host-element-child', MyComponent, {
return [$api.c('x-child', Child, {
attrs: {
'x:title': 'foo',
}
Expand All @@ -131,7 +132,7 @@ describe('html-element', () => {
}
const element = createElement('remove-namespaced-attribute-on-host-element', { is: Parent });
document.body.appendChild(element);
const child = querySelector.call(element, 'remove-namespaced-attribute-on-host-element-child');
const child = querySelector.call(element, 'x-child');
child.removeTitle();
expect(child.hasAttributeNS('x', 'title')).toBe(false);
});
Expand All @@ -152,17 +153,17 @@ describe('html-element', () => {

describe('#removeAttribute()', () => {
it('should remove attribute on host element when element is nested in template', () => {
class MyComponent extends Element {
class Child extends Element {
removeTitle() {
this.removeAttribute('title');
}
}
MyComponent.publicMethods = ['removeTitle'];
Child.publicMethods = ['removeTitle'];

class Parent extends Element {
render() {
return ($api) => {
return [$api.c('element-is-nested-in-template-child', MyComponent, {
return [$api.c('x-child', Child, {
attrs: {
title: 'foo',
}
Expand All @@ -172,7 +173,7 @@ describe('html-element', () => {
}
const element = createElement('element-is-nested-in-template', { is: Parent });
document.body.appendChild(element);
const child = querySelector.call(element, 'element-is-nested-in-template-child');
const child = querySelector.call(element, 'x-child');
child.removeTitle();
expect(child.hasAttribute('title')).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('invoker', () => {
}
}
function html($api) {
return [$api.c('x-foo', Child, {})];
return [$api.c('x-child', Child, {})];
}
class MyComponent3 extends Element {
renderedCallback() {
Expand Down