-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for hapi7 webpack dev plugin
- Loading branch information
Showing
5 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("electrode-server"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
packages/xarc-app-dev/test/spec/webpack-dev-hapi17.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
}); | ||
}); | ||
}); |