Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Improve and Fix some tests #116

Merged
merged 4 commits into from
Jan 8, 2018
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
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = {
extends: [require.resolve('eslint-config-fusion')],
rules: {
'import/no-dynamic-require': 0,
'import/no-webpack-loader-syntax': 0,
}
};
16 changes: 9 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node
/* eslint-env node */
require('./cli-runner').run(process.argv.slice(2).join(' ')).catch(e => {
// eslint-disable-next-line no-console
console.error(e.message);
if (e.yargs) e.yargs.showHelp();
// Rethrow so that there's a non-zero exit code
throw e;
});
require('./cli-runner')
.run(process.argv.slice(2).join(' '))
.catch(e => {
// eslint-disable-next-line no-console
console.error(e.message);
if (e.yargs) e.yargs.showHelp();
// Rethrow so that there's a non-zero exit code
throw e;
});
5 changes: 3 additions & 2 deletions build/babel-plugins/babel-plugin-asseturl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ function refsHandler(t, context, refs = []) {
args[0].replaceWith(
t.callExpression(t.identifier('require'), [
t.stringLiteral(
`__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!${args[0]
.node.value}`
`__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!${
args[0].node.value
}`
),
])
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
const stripIndent = require('strip-indent');

const sharedExpectedContent = stripIndent(
`
import { chunkId as _chunkId } from 'fusion-core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = function doTransform(inputString) {
],
babelPluginSyntaxJsx,
],
}).code
.trim()
})
.code.trim()
// Normalize quotes
.replace(/"/g, "'")
);
Expand Down
1 change: 1 addition & 0 deletions build/babel-plugins/babel-plugin-i18n/test/get-expected.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env node */
const stripIndent = require('strip-indent');
const sharedExpectedContent = require('./shared-expected-content.js');

module.exports = function getExpected(inputString, includeShared = true) {
const sharedContent = includeShared ? '\n' + sharedExpectedContent() : '';
return (stripIndent(inputString).trim() + sharedContent).replace(/"/g, "'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
const stripIndent = require('strip-indent');

module.exports = () =>
stripIndent(
`
Expand Down
4 changes: 2 additions & 2 deletions build/babel-plugins/babel-plugin-i18n/test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = function doTransform(inputString) {
],
babelPluginSyntaxJsx,
],
}).code
.trim()
})
.code.trim()
// Normalize quotes
.replace(/"/g, "'")
);
Expand Down
4 changes: 2 additions & 2 deletions build/babel-plugins/babel-plugin-sw/test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = function doTransform(inputString) {
return (
transform(inputString.trim(), {
plugins: [[plugin]],
}).code
.trim()
})
.code.trim()
// Normalize quotes
.replace(/"/g, "'")
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
/* eslint-env node */
const snakeCase = require('just-snake-case');

module.exports = replaceImportDeclaration;

/*
Expand Down
76 changes: 41 additions & 35 deletions build/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');

const webpack = require('webpack');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');

const progress = new ProgressBarPlugin();
const WebpackChunkHash = require('webpack-chunk-hash');
const webpackDevMiddleware = require('../lib/simple-webpack-dev-middleware');
Expand Down Expand Up @@ -87,12 +88,14 @@ function getConfig({target, env, dir, watch, cover}) {
const destination = path.resolve(dir, `.fusion/dist/${env}/${side}`);
const evergreen = false;
const possibleESVersions = ['es5'];
const serverEntry = env === 'test'
? serverTestEntry
: path.join(__dirname, `../entries/server-entry.js`);
const clientEntry = env === 'test'
? browserTestEntry
: path.join(__dirname, `../entries/client-entry.js`);
const serverEntry =
env === 'test'
? serverTestEntry
: path.join(__dirname, `../entries/server-entry.js`);
const clientEntry =
env === 'test'
? browserTestEntry
: path.join(__dirname, `../entries/client-entry.js`);
const entry = {
node: serverEntry,
web: clientEntry,
Expand Down Expand Up @@ -155,25 +158,27 @@ function getConfig({target, env, dir, watch, cover}) {
* We only use it for generating nice stack traces
*/
// TODO(#6): what about node v8 inspector?
devtool: target !== 'node' && env === 'production'
? 'hidden-source-map'
: 'cheap-module-source-map',
devtool:
target !== 'node' && env === 'production'
? 'hidden-source-map'
: 'cheap-module-source-map',
output: {
// For in-memory filesystem in webpack dev middleware, write files to root
// Otherwise, write to appropriate location on disk
path: env === 'development' && watch && target === 'web'
? '/'
: destination,
filename: env === 'production' && target === 'web'
? `${name}-[name]-[chunkhash].js`
: `${name}-[name].js`,
path:
env === 'development' && watch && target === 'web' ? '/' : destination,
filename:
env === 'production' && target === 'web'
? `${name}-[name]-[chunkhash].js`
: `${name}-[name].js`,
libraryTarget: target === 'node' ? 'commonjs2' : 'var',
// This is the recommended default.
// See https://webpack.js.org/configuration/output/#output-sourcemapfilename
sourceMapFilename: `[file].map`,
chunkFilename: env === 'production' && target === 'web'
? '[id]-[chunkhash].js'
: evergreen ? 'evergreen-[id].js' : '[id].js',
chunkFilename:
env === 'production' && target === 'web'
? '[id]-[chunkhash].js'
: evergreen ? 'evergreen-[id].js' : '[id].js',
// We will set __webpack_public_path__ at runtime, so this should be set to undefined
publicPath: void 0,
// TODO(#7): Do we really need this? See lite config
Expand Down Expand Up @@ -215,8 +220,8 @@ function getConfig({target, env, dir, watch, cover}) {
// Tape also requires __dirname, remove once we don't use tape anymore
__dirname: env === 'test' && target === 'web' ? true : false,
/**
* Tape requires `fs` to be defined
*/
* Tape requires `fs` to be defined
*/
fs: env === 'test' && target === 'web' ? 'empty' : false,
},
node
Expand Down Expand Up @@ -279,15 +284,16 @@ function getConfig({target, env, dir, watch, cover}) {
[
require.resolve('./babel-preset.js'),
{
targets: target === 'node'
? {
node: 'current',
}
: {
browsers: evergreen
? browserSupport.evergreen
: browserSupport.conservative,
},
targets:
target === 'node'
? {
node: 'current',
}
: {
browsers: evergreen
? browserSupport.evergreen
: browserSupport.conservative,
},
},
],
...(fusionConfig.babel && fusionConfig.babel.presets
Expand Down Expand Up @@ -345,13 +351,13 @@ function getConfig({target, env, dir, watch, cover}) {
__ENV__: env,
},
target === 'node' &&
env === 'test' && {
__NODE_TEST_ENTRY__: serverTestEntry,
},
env === 'test' && {
__NODE_TEST_ENTRY__: serverTestEntry,
},
target === 'web' &&
env === 'test' && {
__BROWSER_TEST_ENTRY__: browserTestEntry,
},
env === 'test' && {
__BROWSER_TEST_ENTRY__: browserTestEntry,
},
alias
),
},
Expand Down
27 changes: 15 additions & 12 deletions build/dev-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,21 @@ module.exports.DevelopmentRuntime = function({
state.server = http.createServer((req, res) => {
middleware(req, res, async () => {
const childPort = await state.childPortP;
lifecycle.wait().then(function retry() {
const newUrl = getChildUrl(req.url, {
protocol: 'http',
hostname: 'localhost',
port: childPort,
});
const proxyReq = request(newUrl);
proxyReq.on('error', retry);
req.pipe(proxyReq).pipe(res);
}, error => {
renderError(res, error);
});
lifecycle.wait().then(
function retry() {
const newUrl = getChildUrl(req.url, {
protocol: 'http',
hostname: 'localhost',
port: childPort,
});
const proxyReq = request(newUrl);
proxyReq.on('error', retry);
req.pipe(proxyReq).pipe(res);
},
error => {
renderError(res, error);
}
);
});
});
const listen = promisify(state.server.listen.bind(state.server));
Expand Down
1 change: 1 addition & 0 deletions build/spawn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
const cp = require('child_process');

module.exports = function spawn(commandString) {
const [command, ...args] = commandString.split(' ');
const child = cp.spawn(command, args, {stdio: 'inherit'});
Expand Down
10 changes: 7 additions & 3 deletions commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ exports.builder = {
// default: false,
// describe: 'Debug application',
// },
port: {
type: 'number',
describe:
'Port to start the server on. Defaults to process.env.PORT_HTTP || 3000',
},
dir: {
type: 'string',
default: '.',
Expand All @@ -23,7 +28,7 @@ exports.builder = {
},
};

exports.run = async function({dir = '.', environment}) {
exports.run = async function({dir = '.', environment, port}) {
const getEntry = env => {
const entryPath = `.fusion/dist/${env}/server/server-main.js`;
return path.resolve(dir, entryPath);
Expand All @@ -36,8 +41,7 @@ exports.run = async function({dir = '.', environment}) {
if (env) {
const entry = getEntry(env);
const {start} = require(entry);

return start({port: process.env.PORT_HTTP || 3000}); // handle server bootstrap errors (e.g. port already in use)
return start({port: port || process.env.PORT_HTTP || 3000}); // handle server bootstrap errors (e.g. port already in use)
} else {
throw new Error(`App can't start. JS isn't compiled`); // handle compilation errors
}
Expand Down
1 change: 1 addition & 0 deletions entries/client-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'core-js/es6';
import 'core-js/es7';

// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
import initialize from '__FRAMEWORK_SHARED_ENTRY__';

/*
Expand Down
7 changes: 3 additions & 4 deletions entries/polyfills/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/* eslint-env browser */
/* global setImmediate, setTimeout */

// eslint-disable-next-line import/no-mutable-exports
var Promise = function(executor) {
if (!(this instanceof Promise))
throw new Error('Promise must be called with `new`');
Expand All @@ -20,9 +20,8 @@ var Promise = function(executor) {
resolvers: resolvers,
rejectors: rejectors,
});
var callAsync = typeof setImmediate === 'function'
? setImmediate
: setTimeout;
var callAsync =
typeof setImmediate === 'function' ? setImmediate : setTimeout;
function handler(list, shouldAbsorb) {
return function execute(value) {
var then;
Expand Down
1 change: 1 addition & 0 deletions entries/server-entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
import http from 'http';
// eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
import main from '__FRAMEWORK_SHARED_ENTRY__';
import CompilationMetaDataFactory from '../plugins/compilation-metadata-plugin';
import AssetsFactory from '../plugins/assets-plugin';
Expand Down
1 change: 1 addition & 0 deletions lib/simple-webpack-dev-middleware/lib/Shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const parseRange = require('range-parser');
const pathIsAbsolute = require('path-is-absolute');
const MemoryFileSystem = require('memory-fs');

const HASH_REGEXP = /[0-9a-f]{10,}/;
const EventEmitter = require('events');

Expand Down
Loading