-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
evilebottnawi
committed
Oct 9, 2017
1 parent
820c369
commit 8adae27
Showing
7 changed files
with
91 additions
and
99 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "robotstxt-webpack-plugin", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A webpack plugin to output a robots.txt file", | ||
"license": "MIT", | ||
"author": "itgalaxy <[email protected]>", | ||
|
@@ -73,11 +73,11 @@ | |
}, | ||
"scripts": { | ||
"precommit": "lint-staged", | ||
"lint:prettier": "prettier --list-different '{src,__tests__}/**/*.{js,jsx}' '*.js'", | ||
"lint:prettier": "prettier --list-different '{src,__tests__}/**/*.{js,jsx}' '!src/__tests__/build/**' '*.js'", | ||
"lint:remark": "remark . -i .gitignore -f -q", | ||
"lint:eslint": "eslint . '.*.js' --ignore-path .gitignore --ext '.js,.jsx'", | ||
"lint": "npm-run-all -l -p 'lint:**'", | ||
"fix:prettier": "prettier --write '{src,__tests__}/**/*.{js,jsx}' '*.js'", | ||
"fix:prettier": "prettier --write '{src,__tests__}/**/*.{js,jsx}' '!src/__tests__/build/**' '*.js'", | ||
"fix:eslint": "eslint . '.*.js' --fix --ignore-path .gitignore --ext '.js,.jsx'", | ||
"fix": "npm-run-all -l -p 'fix:**'", | ||
"pretest": "npm run lint", | ||
|
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 |
---|---|---|
@@ -1,108 +1,97 @@ | ||
import RobotstxtPlugin from "../RobotstxtWebpackPlugin"; | ||
import path from "path"; | ||
// eslint-disable-next-line node/no-unpublished-import | ||
import test from "ava"; | ||
// eslint-disable-next-line node/no-unpublished-import | ||
import webpack from "webpack"; | ||
import webpackConfigBase from "./configs/config-base"; | ||
|
||
const robotstxtPluginBaseOptions = {}; | ||
|
||
test.cb("should execute successfully", t => { | ||
t.plan(4); | ||
t.plan(4); | ||
|
||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
|
||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
|
||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets["robots.txt"] !== null, | ||
"robots.txt in assets" | ||
); | ||
t.true(stats.compilation.assets["robots.txt"].size() > 0); | ||
t.true(stats.compilation.assets["robots.txt"].source().length > 0); | ||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets["robots.txt"] !== null, | ||
"robots.txt in assets" | ||
); | ||
t.true(stats.compilation.assets["robots.txt"].size() > 0); | ||
t.true(stats.compilation.assets["robots.txt"].source().length > 0); | ||
|
||
t.end(); | ||
}); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test.cb("should execute successfully without options", t => { | ||
t.plan(4); | ||
t.plan(4); | ||
|
||
webpackConfigBase.plugins = [new RobotstxtPlugin()]; | ||
webpackConfigBase.plugins = [new RobotstxtPlugin()]; | ||
|
||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets["robots.txt"] !== null, | ||
"robots.txt in assets" | ||
); | ||
t.true(stats.compilation.assets["robots.txt"].size() > 0); | ||
t.true(stats.compilation.assets["robots.txt"].source().length > 0); | ||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets["robots.txt"] !== null, | ||
"robots.txt in assets" | ||
); | ||
t.true(stats.compilation.assets["robots.txt"].size() > 0); | ||
t.true(stats.compilation.assets["robots.txt"].source().length > 0); | ||
|
||
t.end(); | ||
}); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test.cb("should execute successfully using `dest` option", t => { | ||
t.plan(4); | ||
|
||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
|
||
options.dest = "build/nested/dir"; | ||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
|
||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets[path.join(options.dest, "robots.txt")] !== | ||
null, | ||
"robots.txt in assets" | ||
); | ||
t.true( | ||
stats.compilation.assets[ | ||
path.join(options.dest, "robots.txt") | ||
].size() > 0 | ||
); | ||
t.true( | ||
stats.compilation.assets[ | ||
path.join(options.dest, "robots.txt") | ||
].source().length > 0 | ||
); | ||
|
||
t.end(); | ||
}); | ||
t.plan(4); | ||
|
||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
|
||
options.filePath = "build/nested/dir/robots.txt"; | ||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
|
||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
t.true(stats.compilation.errors.length === 0, "no compilation error"); | ||
t.true( | ||
stats.compilation.assets[options.filePath] !== null, | ||
"robots.txt in assets" | ||
); | ||
t.true(stats.compilation.assets[options.filePath].size() > 0); | ||
t.true(stats.compilation.assets[options.filePath].source().length > 0); | ||
|
||
t.end(); | ||
}); | ||
}); | ||
|
||
test.cb("should throw error on invalid `generate-robotstxt` options", t => { | ||
t.plan(1); | ||
t.plan(1); | ||
|
||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
const options = Object.assign({}, robotstxtPluginBaseOptions); | ||
|
||
options.policy = {}; | ||
options.policy = {}; | ||
|
||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
webpackConfigBase.plugins = [new RobotstxtPlugin(options)]; | ||
|
||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
webpack(webpackConfigBase, (error, stats) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
t.true(stats.compilation.errors.length === 1, "compilation error"); | ||
t.end(); | ||
}); | ||
t.true(stats.compilation.errors.length === 1, "compilation error"); | ||
t.end(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import path from "path"; | ||
|
||
export default { | ||
entry: path.resolve(__dirname, "../fixtures/entry.js"), | ||
output: { | ||
filename: "bundle.js", | ||
path: path.resolve(__dirname, "../build") | ||
}, | ||
plugins: [], | ||
resolve: { | ||
modules: ["web_modules", "node_modules"] | ||
} | ||
entry: path.resolve(__dirname, "../fixtures/entry.js"), | ||
output: { | ||
filename: "bundle.js", | ||
path: path.resolve(__dirname, "../build") | ||
}, | ||
plugins: [], | ||
resolve: { | ||
modules: ["web_modules", "node_modules"] | ||
} | ||
}; |