Skip to content

Commit

Permalink
Replace RX.helpers, Load Chai to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouncey committed Apr 8, 2018
1 parent 95e3afd commit 5978183
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
35 changes: 21 additions & 14 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,26 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
});
};

exports.modifyWebpackConfig = ({ config, stage, babelConfig }) => {
if (stage === 'build-javascript' || stage === 'develop') {
const generateBabelConfig = require('gatsby/dist/utils/babel-config');

exports.modifyWebpackConfig = ({ config, stage }) => {
const program = {
directory: __dirname,
browserslist: ['> 1%', 'last 2 versions', 'IE >= 9']
};

return generateBabelConfig(program, stage).then(babelConfig => {
config.removeLoader('js').loader('js', {
test: /\.jsx?$/,
exclude: modulePath => {
return (
/node_modules/.test(modulePath) &&
!(/node_modules\/(ansi-styles|chalk)/).test(modulePath)
);
},
loader: 'babel',
query: babelConfig
});
config.plugin('CopyWebpackPlugin', CopyWebpackPlugin, [
[
{
Expand All @@ -93,16 +111,5 @@ exports.modifyWebpackConfig = ({ config, stage, babelConfig }) => {
}
]
]);
// remove the default 'js' loader so we can create our own
config.removeLoader('js');
// these modules are shipped with es6 code, we need to transform them due
// to the version of the uglifyjs plugin gatsby is using
config.loader('js', {
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)\/(?!ansi-styles|chalk)/,
loader: 'babel',
query: babelConfig
});
}
return config;
});
};
9 changes: 9 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ exports.replaceRenderer = ({
);
replaceBodyHTMLString(renderToString(<ConnectedBody />));
};

exports.onRenderBody = ({ setPostBodyComponents }) =>
setPostBodyComponents([
<script
async='true'
key='chai-CDN'
src='https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js'
/>
]);
12 changes: 9 additions & 3 deletions src/client/frame-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ document.addEventListener('DOMContentLoaded', function() {
var testTimeout = 5000;
var Rx = document.Rx;
var frameReady = document.__frameReady;
var helpers = Rx.helpers;
var chai = require('chai');
var chai = parent.chai;
var source = document.__source;
var __getUserInput = document.__getUserInput || (x => x);
var checkChallengePayload = document.__checkChallengePayload;

function isPromise(value) {
return (
value &&
typeof value.subscribe !== 'function' &&
typeof value.then === 'function'
);
}
// Fake Deep Equal dependency
/* eslint-disable no-unused-vars */
const DeepEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
Expand Down Expand Up @@ -105,7 +111,7 @@ document.addEventListener('DOMContentLoaded', function() {
// sync tests can return Any type
__result = test(getUserInput);

if (helpers.isPromise(__result)) {
if (isPromise(__result)) {
// turn promise into an observable
__result = Rx.Observable.fromPromise(__result);
}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/Challenges/utils/ajax-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import debugFactory from 'debug';
import { Observable, helpers } from 'rxjs';
import { Observable, noop } from 'rxjs';

const debug = debugFactory('fcc:ajax$');
const root = typeof window !== 'undefined' ? window : {};
Expand All @@ -42,7 +42,7 @@ function getXMLHttpRequest() {
}
} catch (e) {
// purposely do nothing
helpers.noop(e);
noop.noop(e);
}
}
return new root.ActiveXObject(progId);
Expand Down

0 comments on commit 5978183

Please sign in to comment.