Skip to content

Commit

Permalink
test: improve E2E test (#412)
Browse files Browse the repository at this point in the history
- More accurate versions of peer dependencies which are installed.
- More accurate `eslint` path in a working directory.
- Don't use unsafe `shell: true` option of `execa`.
  • Loading branch information
ybiquitous authored Jun 27, 2019
1 parent f42e6bd commit 8a1ad29
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
49 changes: 46 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"eslint-find-rules": "3.3.1",
"execa": "1.0.0",
"prettier": "1.18.2",
"semver": "^6.1.2",
"tape": "4.10.2",
"typescript": "3.5.2",
"ybiq": "8.0.0"
Expand Down
17 changes: 12 additions & 5 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require("path");
const fs = require("fs");
const { EOL } = require("os");
const semver = require("semver");
const test = require("tape");
const pkg = require("../package.json");
const { sandbox, $, lintConfigFiles } = require("./helper");
Expand All @@ -21,16 +22,22 @@ cache-min=9999
test("End-to-End", t => {
const tarball = $("npm", "pack");
const tarballPath = `file:${path.join(baseDir, tarball)}`;
const peerDeps = Object.entries(pkg.peerDependencies).map(([name, verRange]) => {
const ver = semver.valid(semver.coerce(verRange));
return `${name}@${ver}`;
});

sandbox(() => {
sandbox(cwd => {
fs.writeFileSync(".npmrc", npmrc);

$("npm", "init", "--yes", "--no-init-module");
$("npm", "install", ...Object.keys(pkg.peerDependencies), tarballPath);
$("npm", "install", ...peerDeps, tarballPath);

const eslint = path.join(cwd, "node_modules", ".bin", "eslint");

writeESLintConfig({ extends: "ybiquitous" });
writeLintTargetFile("process.stdout.write(1);");
$("eslint", ".");
$(eslint, ".");
t.pass("default configuration");

lintConfigFiles
Expand All @@ -39,12 +46,12 @@ test("End-to-End", t => {
const configName = `ybiquitous/${path.basename(file, ".js")}`;
writeESLintConfig({ extends: configName });
writeLintTargetFile("process.stdout.write(1);");
$("eslint", ".");
$(eslint, ".");
t.pass(`${configName} configuration`);
});

lintConfigFiles.forEach(file => {
$("eslint", "--print-config", path.join("node_modules", "eslint-config-ybiquitous", file));
$(eslint, "--print-config", path.join("node_modules", "eslint-config-ybiquitous", file));
t.pass(`verify configuration for ${file}`);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const log = msg => {
};

const $ = (cmd, ...args) => {
log(`> ${[cmd, ...args].join(" ")}`);
const { stdout } = execa.sync(cmd, args, { shell: true });
log(`> ${cmd} '${args.join("' '")}'`);
const { stdout } = execa.sync(cmd, args);
const maxLines = 20;
const lines = stdout.split(EOL);
if (lines.length < maxLines) {
Expand Down

0 comments on commit 8a1ad29

Please sign in to comment.