Skip to content

Commit

Permalink
test(helpers): Replace normalize-test-root with augmented placeholder…
Browse files Browse the repository at this point in the history
… serialization
  • Loading branch information
evocateur committed Sep 11, 2018
1 parent ed16536 commit 5880788
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 64 deletions.
22 changes: 0 additions & 22 deletions helpers/normalize-test-root/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions helpers/normalize-test-root/package.json

This file was deleted.

21 changes: 18 additions & 3 deletions helpers/serialize-placeholders/index.js
@@ -1,6 +1,8 @@
"use strict";

const normalizeNewline = require("normalize-newline");
const serializeTempdir = require("@lerna-test/serialize-tempdir");
const serializeWindowsPaths = require("@lerna-test/serialize-windows-paths");
// eslint-disable-next-line node/no-unpublished-require
const LERNA_VERSION = require("../../core/lerna/package.json").version;

Expand Down Expand Up @@ -32,18 +34,31 @@ function stabilizeString(str) {
module.exports = {
test(thing) {
if (isObject(thing) && isString(thing.lerna)) {
// object properties only contain versions
return VERSION_REGEX.test(thing.lerna);
}

// also let through multiline strings so we can always remove redundant quotes
return isString(thing) && (VERSION_REGEX.test(thing) || /\n/.test(thing));
return (
isString(thing) &&
(serializeWindowsPaths.test(thing) ||
serializeTempdir.test(thing) ||
VERSION_REGEX.test(thing) ||
// always remove redundant quotes from multiline strings
/\n/.test(thing))
);
},
serialize(thing, config, indentation, depth, refs, printer) {
if (isString(thing)) {
// this always removes redundant quotes for multiline strings
return stabilizeString(thing);
let val = stabilizeString(thing);

val = serializeWindowsPaths.serialize(val, config, indentation, depth);
val = serializeTempdir.serialize(val, config, indentation, depth);

return val;
}

// object properties only contain versions
// eslint-disable-next-line no-param-reassign
thing.lerna = stableVersion(thing.lerna);

Expand Down
2 changes: 2 additions & 0 deletions helpers/serialize-placeholders/package.json
Expand Up @@ -6,6 +6,8 @@
"private": true,
"license": "MIT",
"dependencies": {
"@lerna-test/serialize-tempdir": "file:../serialize-tempdir",
"@lerna-test/serialize-windows-paths": "file:../serialize-windows-paths",
"normalize-newline": "^3.0.0"
}
}
3 changes: 1 addition & 2 deletions integration/lerna-clean.test.js
Expand Up @@ -4,15 +4,14 @@ const globby = require("globby");

const cliRunner = require("@lerna-test/cli-runner");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const normalizeTestRoot = require("@lerna-test/normalize-test-root");

describe("lerna clean", () => {
test("global", async () => {
const cwd = await initFixture("lerna-clean");
const args = ["clean", "--yes", "--concurrency=1"];

const { stderr } = await cliRunner(cwd)(...args);
expect(normalizeTestRoot(stderr)).toMatchInlineSnapshot(`
expect(stderr).toMatchInlineSnapshot(`
lerna notice cli __TEST_VERSION__
lerna info clean removing __TEST_ROOTDIR__/packages/package-1/node_modules
lerna info clean removing __TEST_ROOTDIR__/packages/package-2/node_modules
Expand Down
4 changes: 0 additions & 4 deletions integration/lerna-ls.test.js
Expand Up @@ -3,10 +3,6 @@
const cliRunner = require("@lerna-test/cli-runner");
const initFixture = require("@lerna-test/init-fixture")(__dirname);

// normalize temp directory paths in snapshots
expect.addSnapshotSerializer(require("@lerna-test/serialize-windows-paths"));
expect.addSnapshotSerializer(require("@lerna-test/serialize-tempdir"));

// ls never makes changes to repo, so we only need one fixture + runner
let lerna;

Expand Down
3 changes: 1 addition & 2 deletions integration/lerna-publish-lifecycle-errors.test.js
Expand Up @@ -9,7 +9,6 @@ const gitCommit = require("@lerna-test/git-commit");
const cloneFixture = require("@lerna-test/clone-fixture")(
path.resolve(__dirname, "../commands/publish/__tests__")
);
const normalizeTestRoot = require("@lerna-test/normalize-test-root");

const env = {
// never actually upload when calling `npm install`
Expand All @@ -35,7 +34,7 @@ test("lerna publish lifecycle scripts stop on non-zero exit", async () => {
await cliRunner(cwd, env)(...args);
} catch (err) {
expect(err.code).toBe(123);
expect(normalizeTestRoot(err.stdout)).toMatchInlineSnapshot(`
expect(err.stdout).toMatchInlineSnapshot(`
Changes:
- package-1: 1.0.0 => 1.1.0
Expand Down
6 changes: 1 addition & 5 deletions integration/lerna-publish-lifecycle-silent.test.js
Expand Up @@ -6,10 +6,6 @@ const cliRunner = require("@lerna-test/cli-runner");
const cloneFixture = require("@lerna-test/clone-fixture")(
path.resolve(__dirname, "../commands/publish/__tests__")
);
const normalizeTestRoot = require("@lerna-test/normalize-test-root");

// stabilize changelog commit SHA and datestamp
expect.addSnapshotSerializer(require("@lerna-test/serialize-changelog"));

const env = {
// never actually upload when calling `npm install`
Expand All @@ -23,7 +19,7 @@ test("lerna publish lifecycle scripts --loglevel=silent", async () => {
const args = ["publish", "minor", "--yes", "--loglevel", "silent", "--no-verify-registry"];

const { stdout } = await cliRunner(cwd, env)(...args);
expect(normalizeTestRoot(stdout)).toMatchInlineSnapshot(`
expect(stdout).toMatchInlineSnapshot(`
Changes:
- package-1: 1.0.0 => 1.1.0
Expand Down
6 changes: 1 addition & 5 deletions integration/lerna-publish-lifecycle.test.js
Expand Up @@ -6,10 +6,6 @@ const cliRunner = require("@lerna-test/cli-runner");
const cloneFixture = require("@lerna-test/clone-fixture")(
path.resolve(__dirname, "../commands/publish/__tests__")
);
const normalizeTestRoot = require("@lerna-test/normalize-test-root");

// stabilize changelog commit SHA and datestamp
expect.addSnapshotSerializer(require("@lerna-test/serialize-changelog"));

const env = {
// never actually upload when calling `npm install`
Expand All @@ -23,7 +19,7 @@ test("lerna publish lifecycle scripts", async () => {
const args = ["publish", "minor", "--yes"];

const { stdout } = await cliRunner(cwd, env)(...args);
expect(normalizeTestRoot(stdout)).toMatchInlineSnapshot(`
expect(stdout).toMatchInlineSnapshot(`
Changes:
- package-1: 1.0.0 => 1.1.0
Expand Down
10 changes: 2 additions & 8 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -41,7 +41,6 @@
"@lerna-test/logging-output": "file:helpers/logging-output",
"@lerna-test/multi-line-trim-right": "file:helpers/multi-line-trim-right",
"@lerna-test/normalize-relative-dir": "file:helpers/normalize-relative-dir",
"@lerna-test/normalize-test-root": "file:helpers/normalize-test-root",
"@lerna-test/pkg-matchers": "file:helpers/pkg-matchers",
"@lerna-test/sawmill": "file:helpers/sawmill",
"@lerna-test/serialize-changelog": "file:helpers/serialize-changelog",
Expand Down

0 comments on commit 5880788

Please sign in to comment.