Skip to content

Commit

Permalink
Run karma tests against build output (#2300)
Browse files Browse the repository at this point in the history
Run karma tests against build output
  • Loading branch information
marvinhagemeister committed Feb 4, 2020
2 parents 19cd1c1 + a6bd55b commit 7ae3be6
Show file tree
Hide file tree
Showing 16 changed files with 731 additions and 224 deletions.
31 changes: 29 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// Only used for mocha tests. For karma, see karma.config.js
module.exports = function(api) {
api.cache(true);

const minify = String(process.env.MINIFY) === 'true';

const rename = {};
const mangle = require('./mangle.json');
for (let prop in mangle.props.props) {
let name = prop;
if (name[0] === '$') {
name = name.slice(1);
}

rename[name] = mangle.props.props[prop];
}

return {
presets: [
[
Expand All @@ -20,6 +32,21 @@ module.exports = function(api) {
'@babel/plugin-transform-react-jsx',
'babel-plugin-transform-async-to-promises'
],
ignore: ['./dist']
include: ['**/src/**/*.js', '**/test/**/*.js'],
overrides: [
{
test(filename) {
const isOptionsTestFile =
filename.endsWith('optionSpies.js') ||
filename.endsWith('.options.test.js');
return minify && isOptionsTestFile;
},
plugins: [['babel-plugin-transform-rename-properties', { rename }]]
},
{
test: /(component-stack|debug)\.test\.js$/,
plugins: ['@babel/plugin-transform-react-jsx-source']
}
]
};
};
39 changes: 35 additions & 4 deletions compat/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,61 @@
"what is this file?": "It controls protected/private property mangling so that minified builds have consistent property names.",
"why are there duplicate minified properties?": "Most properties are only used on one type of objects, so they can have the same name since they will never collide. Doing this reduces size."
},
"minify": {
"mangle": {
"properties": {
"regex": "^_",
"reserved": [
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
"__source",
"__self"
]
}
}
},
"props": {
"cname": 6,
"props": {
"$_afterPaintQueued": "__a",
"$__hooks": "__H",
"$_list": "__",
"$_pendingEffects": "__h",
"$_value": "__",
"$_args": "__H",
"$_factory": "__h",
"$_depth": "__b",
"$_nextDom": "__d",
"$_dirty": "__d",
"$_detachOnNextRender": "__b",
"$_force": "__e",
"$_nextState": "__s",
"$_renderCallbacks": "__h",
"$_vnode": "__v",
"$_children": "__k",
"$_pendingSuspensionCount": "__u",
"$_childDidSuspend": "__c",
"$_suspendedComponentWillUnmount": "__c",
"$_dom": "__e",
"$_component": "__c",
"$__html": "__html",
"$_parent": "__",
"$_pendingError": "__E",
"$_processingException": "__",
"$_context": "__n",
"$_defaultValue": "__",
"$_id": "__c",
"$_parentDom": "__P",
"$_prevState": "__u",
"$_root": "__",
"$_commit": "__c",
"$_pendingSuspensionCount": "__u",
"$_detachOnNextRender": "__b",
"$_diff": "__b",
"$_commit": "__c",
"$_render": "__r",
"$_hook": "__h",
"$_catchError": "__e",
"$_unmount": "_e",
"$_suspendedComponentWillUnmount": "__c"
"$_owner": "__o"
}
}
}
File renamed without changes.
21 changes: 18 additions & 3 deletions debug/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,36 @@
"props": {
"cname": 6,
"props": {
"$_afterPaintQueued": "__a",
"$__hooks": "__H",
"$_list": "__",
"$_pendingEffects": "__h",
"$_value": "__",
"$_args": "__H",
"$_factory": "__h",
"$_depth": "__b",
"$_nextDom": "__d",
"$_dirty": "__d",
"$_prevState": "__u",
"$_detachOnNextRender": "__b",
"$_force": "__e",
"$_nextState": "__s",
"$_renderCallbacks": "__h",
"$_pendingSuspensionCount": "__u",
"$_vnode": "__v",
"$_children": "__k",
"$_pendingSuspensionCount": "__u",
"$_childDidSuspend": "__c",
"$_suspendedComponentWillUnmount": "__c",
"$_dom": "__e",
"$_component": "__c",
"$__html": "__html",
"$_parent": "__",
"$_parentDom": "__P",
"$_pendingError": "__E",
"$_processingException": "__",
"$_context": "__n",
"$_defaultValue": "__",
"$_id": "__c",
"$_parentDom": "__P",
"$_prevState": "__u",
"$_root": "__",
"$_diff": "__b",
"$_commit": "__c",
Expand Down
4 changes: 2 additions & 2 deletions debug/test/browser/debug-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('debug with hooks', () => {
expect(fn).to.not.throw();
});

it('should warn for useless useMemo calls', () => {
it('should warn for useMemo/useCallback without arguments', () => {
const App = () => {
const [people] = useState([40, 20, 60, 80]);
const retiredPeople = useMemo(() => people.filter(x => x >= 60));
Expand All @@ -139,7 +139,7 @@ describe('debug with hooks', () => {
expect(warnings.length).to.equal(2);
});

it('should warn when non-array args is passed', () => {
it('should warn when useMemo is called with non-array args', () => {
const App = () => {
const foo = useMemo(() => 'foo', 12);
return <p>{foo}</p>;
Expand Down
File renamed without changes.
49 changes: 48 additions & 1 deletion devtools/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,56 @@
"properties": {
"regex": "^_",
"reserved": [
"__PREACT_DEVTOOLS__"
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
"__source",
"__self"
]
}
}
},
"props": {
"cname": 6,
"props": {
"$_afterPaintQueued": "__a",
"$__hooks": "__H",
"$_list": "__",
"$_pendingEffects": "__h",
"$_value": "__",
"$_args": "__H",
"$_factory": "__h",
"$_depth": "__b",
"$_nextDom": "__d",
"$_dirty": "__d",
"$_detachOnNextRender": "__b",
"$_force": "__e",
"$_nextState": "__s",
"$_renderCallbacks": "__h",
"$_vnode": "__v",
"$_children": "__k",
"$_suspensions": "__u",
"$_childDidSuspend": "__c",
"$_suspendedComponentWillUnmount": "__c",
"$_dom": "__e",
"$_component": "__c",
"$__html": "__html",
"$_parent": "__",
"$_pendingError": "__E",
"$_processingException": "__",
"$_context": "__n",
"$_defaultValue": "__",
"$_id": "__c",
"$_parentDom": "__P",
"$_prevState": "__u",
"$_root": "__",
"$_diff": "__b",
"$_commit": "__c",
"$_render": "__r",
"$_hook": "__h",
"$_catchError": "__e",
"$_unmount": "_e",
"$_owner": "__o"
}
}
}
43 changes: 40 additions & 3 deletions hooks/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,61 @@
"what is this file?": "It controls protected/private property mangling so that minified builds have consistent property names.",
"why are there duplicate minified properties?": "Most properties are only used on one type of objects, so they can have the same name since they will never collide. Doing this reduces size."
},
"minify": {
"mangle": {
"properties": {
"regex": "^_",
"reserved": [
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
"__source",
"__self"
]
}
}
},
"props": {
"cname": 6,
"props": {
"$_afterPaintQueued": "__a",
"$__hooks": "__H",
"$_list": "__",
"$_pendingEffects": "__h",
"$_value": "__",
"$_args": "__H",
"$_factory": "__h",
"$_depth": "__b",
"$_nextDom": "__d",
"$_dirty": "__d",
"$_detachOnNextRender": "__b",
"$_force": "__e",
"$_nextState": "__s",
"$_renderCallbacks": "__h",
"$_vnode": "__v",
"$_children": "__k",
"$_pendingSuspensionCount": "__u",
"$_childDidSuspend": "__c",
"$_suspendedComponentWillUnmount": "__c",
"$_dom": "__e",
"$_component": "__c",
"$__html": "__html",
"$_parent": "__",
"$_pendingError": "__E",
"$_processingException": "__",
"$_context": "__n",
"$_defaultValue": "__",
"$_id": "__c",
"$_parentDom": "__P",
"$_prevState": "__u",
"$_root": "__",
"$_diff": "__b",
"$_commit": "__c",
"$_render": "__r",
"$_renderCallbacks": "__h",
"$_pendingSuspensionCount": "__u",
"$_hook": "__h",
"$_catchError": "__e",
"$_unmount": "_e"
"$_unmount": "_e",
"$_owner": "__o"
}
}
}
File renamed without changes.
Loading

0 comments on commit 7ae3be6

Please sign in to comment.