Skip to content

Commit

Permalink
scripts and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpigeon committed Jun 22, 2020
1 parent 57b81c1 commit 7760992
Show file tree
Hide file tree
Showing 50 changed files with 498 additions and 101 deletions.
3 changes: 0 additions & 3 deletions internals/flow/CSSModule.js.flow

This file was deleted.

2 changes: 0 additions & 2 deletions internals/flow/WebpackAsset.js.flow

This file was deleted.

Binary file removed internals/img/eslint-padded-90.png
Binary file not shown.
Binary file removed internals/img/eslint-padded.png
Binary file not shown.
Binary file removed internals/img/eslint.png
Binary file not shown.
Binary file removed internals/img/flow-padded-90.png
Binary file not shown.
Binary file removed internals/img/flow-padded.png
Binary file not shown.
Binary file removed internals/img/flow.png
Binary file not shown.
Binary file removed internals/img/jest-padded-90.png
Binary file not shown.
Binary file removed internals/img/jest-padded.png
Binary file not shown.
Binary file removed internals/img/jest.png
Binary file not shown.
Binary file removed internals/img/js-padded.png
Binary file not shown.
Binary file removed internals/img/js.png
Binary file not shown.
Binary file removed internals/img/npm.png
Binary file not shown.
Binary file removed internals/img/react-padded-90.png
Binary file not shown.
Binary file removed internals/img/react-padded.png
Binary file not shown.
Binary file removed internals/img/react-router-padded-90.png
Binary file not shown.
Binary file removed internals/img/react-router-padded.png
Binary file not shown.
Binary file removed internals/img/react-router.png
Binary file not shown.
Binary file removed internals/img/react.png
Binary file not shown.
Binary file removed internals/img/redux-padded-90.png
Binary file not shown.
Binary file removed internals/img/redux-padded.png
Binary file not shown.
Binary file removed internals/img/redux.png
Binary file not shown.
Binary file removed internals/img/webpack-padded-90.png
Binary file not shown.
Binary file removed internals/img/webpack-padded.png
Binary file not shown.
Binary file removed internals/img/webpack.png
Binary file not shown.
Binary file removed internals/img/yarn-padded-90.png
Binary file not shown.
Binary file removed internals/img/yarn-padded.png
Diff not rendered.
Binary file removed internals/img/yarn.png
Diff not rendered.
8 changes: 8 additions & 0 deletions internals/scripts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"no-console": "off",
"global-require": "off",
"import/no-dynamic-require": "off",
"import/no-extraneous-dependencies": "off"
}
}
2 changes: 1 addition & 1 deletion internals/scripts/BabelRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const path = require('path');

require('@babel/register')({
extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'],
cwd: path.join(__dirname, '..', '..'),
cwd: path.join(__dirname, '..', '..')
});
30 changes: 30 additions & 0 deletions internals/scripts/CheckBuildsExist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Check if the renderer and main bundles are built
import path from 'path';
import chalk from 'chalk';
import fs from 'fs';

const mainPath = path.join(__dirname, '..', '..', 'app', 'main.prod.js');
const rendererPath = path.join(
__dirname,
'..',
'..',
'app',
'dist',
'renderer.prod.js'
);

if (!fs.existsSync(mainPath)) {
throw new Error(
chalk.whiteBright.bgRed.bold(
'The main process is not built yet. Build it by running "yarn build-main"'
)
);
}

if (!fs.existsSync(rendererPath)) {
throw new Error(
chalk.whiteBright.bgRed.bold(
'The renderer process is not built yet. Build it by running "yarn build-renderer"'
)
);
}
28 changes: 0 additions & 28 deletions internals/scripts/CheckBuiltsExist.js

This file was deleted.

51 changes: 20 additions & 31 deletions internals/scripts/CheckNativeDep.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,49 @@
// @flow
import fs from 'fs';
import chalk from 'chalk';
import { execSync } from 'child_process';
import { dependencies } from '../../package.json';

(() => {
if (!dependencies) return;

if (dependencies) {
const dependenciesKeys = Object.keys(dependencies);
const nativeDeps = fs
.readdirSync('node_modules')
.filter((folder) => fs.existsSync(`node_modules/${folder}/binding.gyp`));

.filter(folder => fs.existsSync(`node_modules/${folder}/binding.gyp`));
try {
// Find the reason for why the dependency is installed. If it is installed
// because of a devDependency then that is okay. Warn when it is installed
// because of a dependency
const dependenciesObject = JSON.parse(
const { dependencies: dependenciesObject } = JSON.parse(
execSync(`npm ls ${nativeDeps.join(' ')} --json`).toString()
);
const rootDependencies = Object.keys(dependenciesObject.dependencies);
const filteredRootDependencies = rootDependencies.filter((rootDependency) =>
const rootDependencies = Object.keys(dependenciesObject);
const filteredRootDependencies = rootDependencies.filter(rootDependency =>
dependenciesKeys.includes(rootDependency)
);

if (filteredRootDependencies.length > 0) {
const plural = filteredRootDependencies.length > 1;
console.log(`
${chalk.whiteBright.bgYellow.bold('Webpack does not work with native dependencies.')}
${chalk.whiteBright.bgYellow.bold(
'Webpack does not work with native dependencies.'
)}
${chalk.bold(filteredRootDependencies.join(', '))} ${
plural ? 'are native dependencies' : 'is a native dependency'
} and should be installed inside of the "./app" folder.
First uninstall the packages from "./package.json":
${chalk.whiteBright.bgGreen.bold('npm uninstall your-package')}
${chalk.bold('Then, instead of installing the package to the root "./package.json":')}
${chalk.whiteBright.bgRed.bold('npm install your-package --save')}
${chalk.bold('Install the package to "./app/package.json"')}
${chalk.whiteBright.bgGreen.bold('cd ./app && npm install your-package --save')}
Read more about native dependencies at:
First, uninstall the packages from "./package.json":
${chalk.whiteBright.bgGreen.bold('yarn remove your-package')}
${chalk.bold(
'Then, instead of installing the package to the root "./package.json":'
)}
${chalk.whiteBright.bgRed.bold('yarn add your-package')}
${chalk.bold('Install the package to "./app/package.json"')}
${chalk.whiteBright.bgGreen.bold('cd ./app && yarn add your-package')}
Read more about native dependencies at:
${chalk.bold(
'https://github.com/chentsulin/electron-react-boilerplate/wiki/Module-Structure----Two-package.json-Structure'
'https://electron-react-boilerplate.js.org/docs/adding-dependencies/#module-structure'
)}
`);

`);
process.exit(1);
}
} catch (e) {
console.log('Native dependencies could not be checked');
}
})();
}
3 changes: 1 addition & 2 deletions internals/scripts/CheckNodeEnv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow
import chalk from 'chalk';

export default function CheckNodeEnv(expectedEnv: string) {
export default function CheckNodeEnv(expectedEnv) {
if (!expectedEnv) {
throw new Error('"expectedEnv" not set');
}
Expand Down
27 changes: 12 additions & 15 deletions internals/scripts/CheckPortInUse.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// @flow
import chalk from 'chalk';
import detectPort from 'detect-port';

(function CheckPortInUse() {
const port: string = process.env.PORT || '1212';
const port = process.env.PORT || '1212';

detectPort(port, (err: ?Error, availablePort: number) => {
if (port !== String(availablePort)) {
throw new Error(
chalk.whiteBright.bgRed.bold(
`Port "${port}" on "localhost" is already in use. Please use another port. ex: PORT=4343 npm run dev`
)
);
} else {
process.exit(0);
}
});
})();
detectPort(port, (err, availablePort) => {
if (port !== String(availablePort)) {
throw new Error(
chalk.whiteBright.bgRed.bold(
`Port "${port}" on "localhost" is already in use. Please use another port. ex: PORT=4343 yarn dev`
)
);
} else {
process.exit(0);
}
});
5 changes: 5 additions & 0 deletions internals/scripts/CheckYarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (!/yarn\.js$/.test(process.env.npm_execpath || '')) {
console.warn(
"\u001b[33mYou don't seem to be using yarn. This could produce unexpected results.\u001b[39m"
);
}
7 changes: 7 additions & 0 deletions internals/scripts/DeleteSourceMaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import path from 'path';
import rimraf from 'rimraf';

export default function deleteSourceMaps() {
rimraf.sync(path.join(__dirname, '../../app/dist/*.js.map'));
rimraf.sync(path.join(__dirname, '../../app/*.js.map'));
}
15 changes: 9 additions & 6 deletions internals/scripts/ElectronRebuild.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// @flow
import path from 'path';
import { execSync } from 'child_process';
import fs from 'fs';
import dependencies from '../../app/package.json';
import { dependencies } from '../../app/package.json';

const nodeModulesPath = path.join(__dirname, '..', '..', 'app', 'node_modules');

if (Object.keys(dependencies || {}).length > 0 && fs.existsSync(nodeModulesPath)) {
if (
Object.keys(dependencies || {}).length > 0 &&
fs.existsSync(nodeModulesPath)
) {
const electronRebuildCmd =
'../node_modules/.bin/electron-rebuild --parallel --force --types prod,dev,optional --module-dir .';

const cmd =
process.platform === 'win32' ? electronRebuildCmd.replace(/\//g, '\\') : electronRebuildCmd;

process.platform === 'win32'
? electronRebuildCmd.replace(/\//g, '\\')
: electronRebuildCmd;
execSync(cmd, {
cwd: path.join(__dirname, '..', '..', 'app'),
stdio: 'inherit'
});
}
13 changes: 0 additions & 13 deletions internals/scripts/RunTests.js

This file was deleted.

13 changes: 13 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "plugin:testcafe/recommended",
"env": {
"jest/globals": true
},
"plugins": ["jest", "testcafe"],
"rules": {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"no-console": "off"
}
}
13 changes: 13 additions & 0 deletions test/actions/__snapshots__/counter.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`actions should decrement should create decrement action 1`] = `
Object {
"type": "DECREMENT_COUNTER",
}
`;

exports[`actions should increment should create increment action 1`] = `
Object {
"type": "INCREMENT_COUNTER",
}
`;
45 changes: 45 additions & 0 deletions test/actions/counter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { spy } from 'sinon';
import * as actions from '../../app/actions/counter';

describe('actions', () => {
it('should increment should create increment action', () => {
expect(actions.increment()).toMatchSnapshot();
});

it('should decrement should create decrement action', () => {
expect(actions.decrement()).toMatchSnapshot();
});

it('should incrementIfOdd should create increment action', () => {
const fn = actions.incrementIfOdd();
expect(fn).toBeInstanceOf(Function);
const dispatch = spy();
const getState = () => ({ counter: 1 });
fn(dispatch, getState);
expect(dispatch.calledWith({ type: actions.INCREMENT_COUNTER })).toBe(true);
});

it('should incrementIfOdd shouldnt create increment action if counter is even', () => {
const fn = actions.incrementIfOdd();
const dispatch = spy();
const getState = () => ({ counter: 2 });
fn(dispatch, getState);
expect(dispatch.called).toBe(false);
});

// There's no nice way to test this at the moment...
it('should incrementAsync', () => {
return new Promise(resolve => {
const fn = actions.incrementAsync(1);
expect(fn).toBeInstanceOf(Function);
const dispatch = spy();
fn(dispatch);
setTimeout(() => {
expect(dispatch.calledWith({ type: actions.INCREMENT_COUNTER })).toBe(
true
);
resolve();
}, 5);
});
});
});
Loading

0 comments on commit 7760992

Please sign in to comment.