Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ce1134 #1474

Merged
merged 3 commits into from
Dec 20, 2019
Merged

Ce1134 #1474

Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";
/* eslint-disable no-console, no-magic-numbers */

const fastifyPlugin = require("fastify-plugin");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add this to dependencies


const archetype = require("electrode-archetype-react-app/config/archetype");

const AppDevMiddleware = require("./app-dev-middleware");

async function register(server) {
if (!archetype.webpack.devMiddleware) {
console.error(
"dev-fastify plugin was loaded but WEBPACK_DEV_MIDDLEWARE is not true. Skipping."
);
return;
}

const middleware = new AppDevMiddleware({});

middleware.setup();

server.addHook("onRequest", async request => {
request.app.webpackDev = middleware.webpackDev;
});

return;
}

module.exports = fastifyPlugin(register, {
name: "electrode-archetype-react-app-dev"
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const WebpackDevRelay = require("../../../lib/dev-admin/webpack-dev-relay");
const { asyncVerify } = require("run-verify");
const _ = require("lodash");

describe.only("webpack-dev-relay", function() {
describe("webpack-dev-relay", function() {
it("should clear webpack dev data if dev server exits", () => {
const wdr = new WebpackDevRelay();
const wds = new EventEmitter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use strict";
const mockRequire = require("mock-require");

describe("dev-fastify", function() {
let fakeServer;
let hooks;
const webpackConfig = {
devMiddleware: true
};

before(() => {
mockRequire("fastify-plugin", (register, params) => {
return {
isMockFastifyPlugin: true,
register,
params
};
});
mockRequire("electrode-archetype-react-app/config/archetype", {
webpack: webpackConfig
});
});

beforeEach(() => {
hooks = {};
webpackConfig.devMiddleware = true;
fakeServer = {
addHook: (event, func) => {
hooks[event] = func;
}
};
});

it("fastify exports module", () => {
const fastifyMod = require("../../lib/webpack-dev-fastify");
expect(fastifyMod.isMockFastifyPlugin).true;
expect(fastifyMod.params.name).eq("electrode-archetype-react-app-dev");
expect(fastifyMod.register).exist;
});

it("if WEBPACK_DEV_MIDDLEWARE is not true, skip with console log", () => {
webpackConfig.devMiddleware = false;
const fastifyMod = require("../../lib/webpack-dev-fastify");
expect(fastifyMod.isMockFastifyPlugin).true;
expect(fastifyMod.register).exist;
fastifyMod.register(fakeServer);
expect(hooks.onRequest).not.exist;
});
it("on request hook is attached", () => {
const fastifyMod = require("../../lib/webpack-dev-fastify");
expect(fastifyMod.isMockFastifyPlugin).true;
expect(fastifyMod.register).exist;
fastifyMod.register(fakeServer);
expect(hooks.onRequest).exist;
});

it("calling request hook sets webpackDev", () => {
const fastifyMod = require("../../lib/webpack-dev-fastify");
expect(fastifyMod.isMockFastifyPlugin).true;
expect(fastifyMod.register).exist;
fastifyMod.register(fakeServer);
expect(hooks.onRequest).exist;
const fakeRequest = {
app: {}
};
hooks.onRequest(fakeRequest);
expect(fakeRequest.app.webpackDev).exist;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("generate-config", function() {
describe("generateConfig", () => {
it("If the configFilename is development.js and only webpack.config.development.js exists, fall back to archetype webpack", () => {
const { generateConfig } = require(moduleName);
const configFilename = "development.js";
const configFilename = "webpack.config.dev.js";
const defaultFilename = "webpack.config.development.js";

const defaultWebpackPath = Path.join(process.cwd(), defaultFilename);
Expand All @@ -44,7 +44,7 @@ describe("generate-config", function() {
}
},
profileNames: [ "_base", "_production" ],
configFilename
configFilename: "development.js"
}, true);

expect(config).to.deep.equal(archWebpackContents);
Expand Down Expand Up @@ -87,9 +87,10 @@ describe("generate-config", function() {

it("If the configName is coverage.js and only coverage.js exists, fall back to archetype webpack", () => {
const { generateConfig } = require(moduleName);
const configFilename = "coverage.js";
const defaultFilename = "coverage.js";
const configFilename = "webpack.config.coverage.js";

const configWebpackPath = Path.join(process.cwd(), configFilename);
const configWebpackPath = Path.join(process.cwd(), defaultFilename);
const configWebpackContents = {test: 5};
mockRequire(configWebpackPath, configWebpackContents);

Expand All @@ -107,7 +108,7 @@ describe("generate-config", function() {
}
},
profileNames: [ "_base", "_production" ],
configFilename
configFilename: "coverage.js"
}, true);

expect(config).to.deep.equal(archWebpackContents);
Expand Down Expand Up @@ -151,12 +152,13 @@ describe("generate-config", function() {
it("If the configName is production.js and only production.js exists, fall back to archetype webpack", () => {
const { generateConfig } = require(moduleName);
const configFilename = "production.js";
const archFilename = "webpack.config.js";

const configWebpackPath = Path.join(process.cwd(), configFilename);
const configWebpackContents = {test: 9};
mockRequire(configWebpackPath, configWebpackContents);

const archWebpackPath = Path.join(Path.resolve("archetype/config/webpack"), configFilename);
const archWebpackPath = Path.join(Path.resolve("archetype/config/webpack"), archFilename);
const archWebpackContents = {test: 10};
mockRequire(archWebpackPath, archWebpackContents);

Expand All @@ -182,13 +184,14 @@ describe("generate-config", function() {
it("If the configName is production.js and only webpack.config.production.js exists, fall back to archetype webpack", () => {
const { generateConfig } = require(moduleName);
const configFilename = "production.js";
const archFilename = "webpack.config.js";
const defaultFilename = "webpack.config.production.js";

const configWebpackPath = Path.join(process.cwd(), defaultFilename);
const configWebpackContents = {test: 11};
mockRequire(configWebpackPath, configWebpackContents);

const archWebpackPath = Path.join(Path.resolve("archetype/config/webpack"), configFilename);
const archWebpackPath = Path.join(Path.resolve("archetype/config/webpack"), archFilename);
const archWebpackContents = {test: 12};
mockRequire(archWebpackPath, archWebpackContents);

Expand Down