Skip to content

Commit

Permalink
add tests for hapi7 webpack dev plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Oct 7, 2020
1 parent 37fe2a2 commit 5497ffe
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/xarc-app-dev/e1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("electrode-server");
15 changes: 15 additions & 0 deletions packages/xarc-app-dev/e1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "e1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"electrode-server": "^1",
"hapi": "^16"
}
}
7 changes: 5 additions & 2 deletions packages/xarc-app-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"@xarc/run": "^1.0.3",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"e1": "./e1",
"electrode-server": "^3.2.0",
"eslint": "^6.8.0",
"eslint-config-walmart": "^2.2.1",
"eslint-plugin-filenames": "^1.1.0",
Expand All @@ -119,7 +121,7 @@
"mock-require": "^3.0.3",
"nyc": "^15.0.0",
"prettier": "^1.14.2",
"run-verify": "^1.2.1",
"run-verify": "^1.2.5",
"shx": "^0.3.2",
"sinon": "^7.2.6",
"sinon-chai": "^3.3.0",
Expand All @@ -139,7 +141,8 @@
"subapp-util": "../subapp-util"
},
"devDependencies": {
"@xarc/app": "../xarc-app"
"@xarc/app": "../xarc-app",
"e1": "./e1"
}
},
"nyc": {
Expand Down
87 changes: 87 additions & 0 deletions packages/xarc-app-dev/test/spec/webpack-dev-hapi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/ban-ts-ignore, no-invalid-this, @typescript-eslint/class-name-casing */

const hapiCompat = require("electrode-hapi-compat");

const moduleName = "../../src/lib/webpack-dev-hapi";

import { asyncVerify, runFinally } from "run-verify";
import { expect } from "chai";
import { before, beforeEach, describe, it, after, afterEach } from "mocha";
const electrodeServer = require("e1");

describe("dev-hapi 16", function() {
this.timeout(10000);

before(() => {
hapiCompat.hapiVersion = 16;
});

beforeEach(() => {
delete require.cache[require.resolve(moduleName)];
});

afterEach(() => {
delete require.cache[require.resolve(moduleName)];
});

after(() => {
//
});

const captureRequest = server => {
const data: any = {};
server.route({
method: "GET",
path: "/test",
handler: (request, reply) => {
data.request = request;
data.called = true;
debugger;
reply("DONE");
}
});
return data;
};

const testPlugin16 = options => {
let server, data;
return asyncVerify(
() => electrodeServer(options),
s => {
server = s;
data = captureRequest(server);

return server.inject("/test");
},
resp => {
expect(resp.statusCode).to.equal(200);
expect(data.request.app)
.to.have.key("webpackDev")
.that.is.an("object");
},
runFinally(() => server.stop())
);
};

it.only("should allow registering the webpack dev plugin for hapi <=16", () => {
return testPlugin16({
plugins: {
"webpack-dev": {
module: moduleName,
requireFromPath: __dirname
}
}
});
});

// it("should allow using the hapi17 register function directly", () => {
// return testPlugin17({
// plugins: {
// "webpack-dev": {
// register: ver17Register
// }
// }
// });
// });
});
85 changes: 85 additions & 0 deletions packages/xarc-app-dev/test/spec/webpack-dev-hapi17.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/ban-ts-ignore, no-invalid-this, @typescript-eslint/class-name-casing */

const hapiCompat = require("electrode-hapi-compat");
const ver17Register = require("../../src/lib/webpack-dev-hapi17");

const moduleName = "../../src/lib/webpack-dev-hapi";

import { asyncVerify, runFinally } from "run-verify";
import { expect } from "chai";
import { before, beforeEach, describe, it, after, afterEach } from "mocha";
const electrodeServer = require("electrode-server");

describe("dev-hapi 17", function() {
this.timeout(10000);

before(() => {
hapiCompat.hapiVersion = 18;
});

beforeEach(() => {});

afterEach(() => {
delete require.cache[require.resolve(moduleName)];
});

after(() => {
//
});

const captureRequest = server => {
const data: any = {};
server.route({
method: "GET",
path: "/test",
handler: (request, h) => {
data.request = request;
data.called = true;
return "DONE";
}
});
return data;
};

const testPlugin17 = options => {
let server, data;
return asyncVerify(
() => electrodeServer(options),
s => {
server = s;
data = captureRequest(server);

return server.inject("/test");
},
resp => {
expect(resp.statusCode).to.equal(200);
expect(data.request.app)
.to.have.key("webpackDev")
.that.is.an("object");
},
runFinally(() => server.stop())
);
};

it("should allow registering the webpack dev plugin for hapi >=18", () => {
return testPlugin17({
plugins: {
"webpack-dev": {
module: moduleName,
requireFromPath: __dirname
}
}
});
});

it("should allow using the hapi17 register function directly", () => {
return testPlugin17({
plugins: {
"webpack-dev": {
register: ver17Register
}
}
});
});
});

0 comments on commit 5497ffe

Please sign in to comment.