Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 2388cac

Browse files
authored
Merge pull request #11 from mongodb-js/feature/electron-renderer-tests
[COMPASS-1785] Support Electron Renderer Tests
2 parents 356a2da + dcce7d0 commit 2388cac

24 files changed

+326
-112
lines changed

template/.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig helps developers define and maintain
2+
# consistent coding styles between different editors and IDEs.
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_style = space
9+
indent_size = 2
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
insert_final_newline = false
16+
trim_trailing_whitespace = false

template/config/webpack.dev.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ module.exports = {
4646
fonts: path.join(project.path.src, 'assets/fonts'),
4747
images: path.join(project.path.src, 'assets/images'),
4848
less: path.join(project.path.src, 'assets/less'),
49+
models: path.join(project.path.src, 'models'),
4950
plugin: path.join(project.path.src, 'index.js'),
5051
stores: path.join(project.path.src, 'stores'),
51-
storybook: project.path.storybook
52+
storybook: project.path.storybook,
53+
utils: path.join(project.path.src, 'utils')
5254
}
5355
},
5456
module: {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const project = require('./project');
4+
5+
const GLOBALS = {
6+
'process.env': {
7+
'NODE_ENV': JSON.stringify('test')
8+
},
9+
__DEV__: JSON.stringify(JSON.parse(process.env.DEBUG || 'true'))
10+
};
11+
12+
module.exports = {
13+
target: 'electron-renderer', // webpack should compile node compatible code for tests
14+
stats: 'errors-only',
15+
externals: {
16+
'jsdom': 'window',
17+
'react/addons': 'react',
18+
'react/lib/ExecutionEnvironment': 'react',
19+
'react/lib/ReactContext': 'react',
20+
'react-addons-test-utils': 'react-dom',
21+
},
22+
resolve: {
23+
modules: ['node_modules'],
24+
extensions: ['.js', '.jsx', '.json', 'less'],
25+
alias: {
26+
actions: path.join(project.path.src, 'actions'),
27+
components: path.join(project.path.src, 'components'),
28+
constants: path.join(project.path.src, 'constants'),
29+
fonts: path.join(project.path.src, 'assets/fonts'),
30+
images: path.join(project.path.src, 'assets/images'),
31+
less: path.join(project.path.src, 'assets/less'),
32+
models: path.join(project.path.src, 'models'),
33+
plugin: path.join(project.path.src, 'index.js'),
34+
stores: path.join(project.path.src, 'stores'),
35+
storybook: project.path.storybook,
36+
utils: path.join(project.path.src, 'utils')
37+
}
38+
},
39+
module: {
40+
rules: [
41+
{
42+
test: /\.css$/,
43+
use: [
44+
{ loader: 'style-loader'},
45+
{ loader: 'css-loader' }
46+
]
47+
},
48+
{
49+
test: /\.less$/,
50+
exclude: /node_modules/,
51+
use: [
52+
{ loader: 'style-loader' },
53+
{
54+
loader: 'css-loader',
55+
options: {
56+
modules: true,
57+
importLoaders: 1,
58+
localIdentName: 'QueryHistory_[name]-[local]__[hash:base64:5]'
59+
}
60+
},
61+
{
62+
loader: 'postcss-loader',
63+
options: {
64+
plugins: function () {
65+
return [
66+
project.plugin.autoprefixer
67+
];
68+
}
69+
}
70+
},
71+
{
72+
loader: 'less-loader',
73+
options: {
74+
noIeCompat: true
75+
}
76+
}
77+
]
78+
},
79+
{
80+
test: /node_modules\/JSONStream\/index\.js$/,
81+
use: [{ loader: 'shebang-loader' }]
82+
},
83+
{
84+
test: /\.(js|jsx)$/,
85+
use: [{ loader: 'babel-loader' }],
86+
exclude: /(node_modules)/
87+
},
88+
{
89+
test: /\.(png|jpg|jpeg|gif|svg)$/,
90+
use: [{
91+
loader: 'ignore-loader',
92+
query: {
93+
limit: 8192,
94+
name: 'assets/images/[name]__[hash:base64:5].[ext]'
95+
}
96+
}]
97+
},
98+
{
99+
test: /\.(woff|woff2|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
100+
use: [{
101+
loader: 'ignore-loader',
102+
query: {
103+
limit: 8192,
104+
name: 'assets/fonts/[name]__[hash:base64:5].[ext]'
105+
}
106+
}],
107+
}
108+
]
109+
}
110+
};

template/config/webpack.prod.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ module.exports = {
4141
fonts: path.join(project.path.src, 'assets/fonts'),
4242
images: path.join(project.path.src, 'assets/images'),
4343
less: path.join(project.path.src, 'assets/less'),
44+
models: path.join(project.path.src, 'models'),
4445
plugin: path.join(project.path.src, 'index.js'),
4546
stores: path.join(project.path.src, 'stores'),
46-
storybook: project.path.storybook
47+
storybook: project.path.storybook,
48+
utils: path.join(project.path.src, 'utils')
4749
}
4850
},
4951
module: {

template/config/webpack.test.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ module.exports = {
2929
fonts: path.join(project.path.src, 'assets/fonts'),
3030
images: path.join(project.path.src, 'assets/images'),
3131
less: path.join(project.path.src, 'assets/less'),
32+
models: path.join(project.path.src, 'models'),
3233
plugin: path.join(project.path.src, 'index.js'),
3334
stores: path.join(project.path.src, 'stores'),
34-
storybook: project.path.storybook
35+
storybook: project.path.storybook,
36+
utils: path.join(project.path.src, 'utils')
3537
}
3638
},
3739
module: {

template/config/webpack.watch.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ module.exports = {
3535
fonts: path.join(project.path.src, 'assets/fonts'),
3636
images: path.join(project.path.src, 'assets/images'),
3737
less: path.join(project.path.src, 'assets/less'),
38+
models: path.join(project.path.src, 'models'),
3839
plugin: path.join(project.path.src, 'index.js'),
3940
stores: path.join(project.path.src, 'stores'),
40-
storybook: project.path.storybook
41+
storybook: project.path.storybook,
42+
utils: path.join(project.path.src, 'utils')
4143
}
4244
},
4345
module: {

template/karma.conf.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const webpackConfig = require('./config/webpack.karma.config');
2+
3+
module.exports = function(config) {
4+
config.set({
5+
basePath: '',
6+
singleRun: true,
7+
files: [
8+
'test/**/*.spec.js'
9+
],
10+
reporters: ['mocha'],
11+
preprocessors: {
12+
'test/**/*.spec.js': ['webpack', 'sourcemap']
13+
},
14+
browsers: ['Electron'],
15+
frameworks: ['mocha', 'chai', 'sinon', 'chai-sinon'],
16+
webpack: webpackConfig,
17+
webpackMiddleware: {
18+
noInfo: true,
19+
stats: 'errors-only'
20+
},
21+
// DEV: `useIframe: false` is for launching a new window instead of using an iframe
22+
// In Electron, iframes don't get `nodeIntegration` priveleges yet windows do.
23+
client: {
24+
useIframe: false
25+
},
26+
logLevel: config.LOG_ERROR
27+
});
28+
};

template/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"start:prod": "npm run compile && electron --noDevServer ./electron",
1414
"test": "cross-env NODE_ENV=test mocha-webpack \"./src/**/*.spec.js\"",
1515
"test:watch": "cross-env NODE_ENV=test mocha-webpack \"./src/**/*.spec.js\" --watch",
16+
"test:karma": "cross-env NODE_ENV=test karma start",
1617
"cover": "nyc npm run test",
1718
"ci": "npm run check && npm test",
1819
"fmt": "mongodb-js-fmt ./*.js ./test/*.js",
@@ -63,6 +64,15 @@
6364
"istanbul-instrumenter-loader": "^3.0.0",
6465
"jsdom": "^11.1.0",
6566
"jsdom-global": "^3.0.2",
67+
"karma": "^1.7.0",
68+
"karma-chai": "^0.1.0",
69+
"karma-chai-sinon": "^0.1.5",
70+
"karma-electron": "^5.2.1",
71+
"karma-mocha": "^1.3.0",
72+
"karma-mocha-reporter": "^2.2.4",
73+
"karma-sinon": "^1.0.5",
74+
"karma-sourcemap-loader": "^0.3.7",
75+
"karma-webpack": "^2.0.4",
6676
"less": "^2.7.2",
6777
"less-loader": "^4.0.5",
6878
"mocha": "^3.4.2",

template/src/actions/actions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Reflux from 'reflux';
2+
3+
const {{pascalcase name}}Actions = Reflux.createActions([
4+
/**
5+
* define your actions as strings below, for example:
6+
*/
7+
'toggleStatus'
8+
]);
9+
10+
export default {{pascalcase name}}Actions;
11+
export { {{pascalcase name}}Actions };

template/src/actions/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
const Reflux = require('reflux');
1+
import {{pascalcase name}}Actions from './actions';
22

3-
const {{pascalcase name}}Actions = Reflux.createActions([
4-
/**
5-
* define your actions as strings below, for example:
6-
*/
7-
'toggleStatus'
8-
]);
9-
10-
module.exports = {{pascalcase name}}Actions;
3+
export default {{pascalcase name}}Actions;
4+
export { {{pascalcase name}}Actions };
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ToggleButton from './ToggleButton';
1+
import ToggleButton from './toggle-button';
22

33
export default ToggleButton;
44
export { ToggleButton };

template/src/components/toggleButton/ToggleButton.jsx renamed to template/src/components/toggle-button/toggle-button.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44

5-
import styles from './ToggleButton.less';
5+
import styles from './toggle-button.less';
66

77
class ToggleButton extends Component {
88
static displayName = 'ToggleButton';

template/src/components/toggleButton/ToggleButton.spec.js renamed to template/src/components/toggle-button/toggle-button.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33

4-
import ToggleButton from 'components/toggleButton';
5-
import styles from './ToggleButton.less';
4+
import ToggleButton from 'components/toggle-button';
5+
import styles from './toggle-button.less';
66

77
describe('ToggleButton [Component]', () => {
88
let component;

template/src/components/toggleButton/ToggleButton.stories.js renamed to template/src/components/toggle-button/toggle-button.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { storiesOf } from '@storybook/react';
55
import { action } from '@storybook/addon-actions';
66
import ComponentPreview from 'storybook/decorators/componentPreview';
77
import { withChaptersOptions } from 'constants/storybook';
8-
import { ToggleButton } from 'components/toggleButton';
8+
import { ToggleButton } from 'components/toggle-button';
99

1010
storiesOf('ToggleButton', module)
1111
.addWithChapters('Example Title', {

template/src/components/{{name}}/{{name}}.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
4-
import ToggleButton from 'components/toggleButton';
4+
import ToggleButton from 'components/toggle-button';
55

66
import styles from './{{name}}.less';
77

template/src/components/{{name}}/{{name}}.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { mount } from 'enzyme';
33

44
import {{pascalcase name}} from 'components/{{name}}';
5-
import ToggleButton from 'components/toggleButton';
5+
import ToggleButton from 'components/toggle-button';
66
import styles from './{{name}}.less';
77

88
describe('{{pascalcase name}} [Component]', () => {

template/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {{pascalcase name}}Plugin from './Plugin';
1+
import {{pascalcase name}}Plugin from './plugin';
22
import {{pascalcase name}}Actions from 'actions';
33
import {{pascalcase name}}Store from 'stores';
44

File renamed without changes.

template/src/Plugin.spec.js renamed to template/src/plugin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33
import { StoreConnector } from 'hadron-react-components';
4-
import {{pascalcase name}}Plugin from './Plugin';
4+
import {{pascalcase name}}Plugin from './plugin';
55

66
describe('{{pascalcase name}} [Plugin]', () => {
77
let component;

0 commit comments

Comments
 (0)