/
lerna-run-nx-env-files.ts
122 lines (84 loc) · 3.47 KB
/
lerna-run-nx-env-files.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { remove, writeFile } from "fs-extra";
import { Fixture } from "../../utils/fixture";
import { normalizeCommandOutput, normalizeEnvironment } from "../../utils/snapshot-serializer-utils";
expect.addSnapshotSerializer({
serialize(str: string) {
return normalizeCommandOutput(normalizeEnvironment(str));
},
test(val: string) {
return val != null && typeof val === "string";
},
});
describe("lerna-run-nx-env-files", () => {
let fixture: Fixture;
beforeEach(async () => {
fixture = await Fixture.create({
name: "lerna-run-nx-env-files",
packageManager: "npm",
initializeGit: true,
runLernaInit: true,
installDependencies: true,
/**
* Because lerna run involves spawning further child processes, the tests would be too flaky
* if we didn't force deterministic terminal output by appending stderr to stdout instead
* of interleaving them.
*/
forceDeterministicTerminalOutput: true,
});
await writeFile(fixture.getWorkspacePath(".env"), `SOMETHING_IN_ENV_FILE=some_value_here`, "utf-8");
await fixture.lerna("create package-1 -y");
await fixture.addScriptsToPackage({
packagePath: "packages/package-1",
scripts: {
"log-env-var": "echo $SOMETHING_IN_ENV_FILE",
},
});
});
afterEach(() => fixture.destroy());
describe("without nx enabled", () => {
it("should log an empty value", async () => {
// Enable legacy task runner
await fixture.overrideLernaConfig({
useNx: false,
});
const output = await fixture.lerna("run log-env-var -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
lerna notice cli v999.9.9-e2e.0
lerna info Executing command in 1 package: "npm run log-env-var --silent"
lerna info run Ran npm script 'log-env-var' in 'package-X' in X.Xs:
lerna success run Ran npm script 'log-env-var' in 1 package in X.Xs:
lerna success - package-X
`);
});
});
describe("with nx enabled", () => {
it("should log a value by default", async () => {
await fixture.addNxJsonToWorkspace();
const output = await fixture.lerna("run log-env-var -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> Lerna (powered by Nx) Nx didn't recognize the following args: loadDotEnvFiles
When using '--' all executor args have to be defined after '--'.
> package-X:log-env-var --silent
> package-X@0.0.0 log-env-var
> echo $SOMETHING_IN_ENV_FILE "--silent"
some_value_here --silent
> Lerna (powered by Nx) Successfully ran target log-env-var for project package-X
lerna notice cli v999.9.9-e2e.0
`);
});
it("should log an empty value when --load-env-files=false", async () => {
await fixture.addNxJsonToWorkspace();
const output = await fixture.lerna("run log-env-var --load-env-files=false -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> Lerna (powered by Nx) Nx didn't recognize the following args: loadDotEnvFiles
When using '--' all executor args have to be defined after '--'.
> package-X:log-env-var --silent
> package-X@0.0.0 log-env-var
> echo $SOMETHING_IN_ENV_FILE "--silent"
--silent
> Lerna (powered by Nx) Successfully ran target log-env-var for project package-X
lerna notice cli v999.9.9-e2e.0
`);
});
});
});