Skip to content

Commit

Permalink
manage: Moved test to folder example
Browse files Browse the repository at this point in the history
Signed-off-by: Jaid <jaid.jsx@gmail.com>
  • Loading branch information
Jaid committed Dec 21, 2019
1 parent c06c8db commit 6f1e84e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {CleanWebpackPlugin} = require("clean-webpack-plugin")
const path = require("path")

/**
* @function
* @param {Object} TestPlugin
* @return {import("webpack").Configuration}
*/
module.exports = TestPlugin => {
return {
mode: "production",
context: path.join(__dirname, "..", "example"),
entry: path.join(__dirname, "..", "example", "src"),
output: {
path: path.join(__dirname, "..", "example", "dist"),
filename: "index.js",
},
plugins: [
new CleanWebpackPlugin,
new TestPlugin,
],
}
}
File renamed without changes.
23 changes: 3 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fsp from "@absolunet/fsp"
import {CleanWebpackPlugin} from "clean-webpack-plugin"
import ms from "ms.macro"
import path from "path"
import pify from "pify"
Expand All @@ -10,30 +9,14 @@ const {default: PkgBannerPlugin} = indexModule

jest.setTimeout(ms`1 minute`)

const getWebpackConfig = name => ({
mode: "production",
context: path.join(__dirname, name),
entry: path.join(__dirname, name),
output: {
path: path.join(__dirname, "..", "dist", "test", name),
filename: "index.js",
},
})

it("should run", async () => {
const name = "basic"
const webpackConfig = {
...getWebpackConfig(name),
plugins: [
new CleanWebpackPlugin,
new PkgBannerPlugin,
],
}
const generateWebpackConfig = require(path.join(__dirname, "..", "example", "webpack.config.js"))
const webpackConfig = generateWebpackConfig(PkgBannerPlugin)
await pify(webpack)(webpackConfig)
const outputFile = path.join(webpackConfig.output.path, webpackConfig.output.filename)
const exists = await fsp.pathExists(outputFile)
expect(exists).toBeTruthy()
const output = await fsp.readFile(outputFile, "utf8")
const expectedBanner = await fsp.readFile(path.join(__dirname, "basic", "expected.txt"), "utf8")
const expectedBanner = await fsp.readFile(path.join(__dirname, "expected.txt"), "utf8")
expect(output.startsWith(expectedBanner)).toBeTruthy()
})

0 comments on commit 6f1e84e

Please sign in to comment.