Skip to content

Commit 457d33f

Browse files
committed
test: stop leaking isInteractive out of project-commands
The beforeEach assigned helpers.isInteractive = () => true and never put it back. Under mocha every test file shares one module registry, so from the moment this file ran, everything after it saw an interactive terminal regardless of the environment - which is why project-name-service passed in CI despite depending on the non-interactive path, and why it only failed once per-file isolation removed the leak. Uses setIsInteractive(), the override the helper already exposes for this, with an afterEach to restore - matching how project-name-service pins it.
1 parent db3aedb commit 457d33f

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

test/project-commands.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Yok } from "../lib/common/yok";
22
import * as stubs from "./stubs";
33
import { CreateProjectCommand } from "../lib/commands/create-project";
44
import { StringCommandParameter } from "../lib/common/command-params";
5-
import * as helpers from "../lib/common/helpers";
5+
import { setIsInteractive } from "../lib/common/helpers";
66
import * as constants from "../lib/constants";
77
import { assert } from "chai";
88
import { PrompterStub } from "./stubs";
@@ -132,7 +132,7 @@ class ProjectServiceMock implements IProjectService {
132132
}
133133

134134
async createProject(
135-
projectOptions: IProjectSettings
135+
projectOptions: IProjectSettings,
136136
): Promise<ICreateProjectData> {
137137
createProjectCalledWithForce = projectOptions.force;
138138
selectedTemplateName = projectOptions.template;
@@ -220,8 +220,7 @@ describe("Project commands tests", () => {
220220

221221
beforeEach(() => {
222222
testInjector = createTestInjector();
223-
// @ts-expect-error
224-
helpers.isInteractive = () => true;
223+
setIsInteractive(() => true);
225224
isProjectCreated = false;
226225
validateProjectCallsCount = 0;
227226
createProjectCalledWithForce = false;
@@ -230,6 +229,10 @@ describe("Project commands tests", () => {
230229
createProjectCommand = testInjector.resolve("$createCommand");
231230
});
232231

232+
afterEach(() => {
233+
setIsInteractive();
234+
});
235+
233236
describe("#CreateProjectCommand", () => {
234237
it("should not fail when using only --ng.", async () => {
235238
options.ng = true;
@@ -366,7 +369,7 @@ describe("Project commands tests", () => {
366369

367370
assert.deepStrictEqual(
368371
selectedTemplateName,
369-
"@nativescript/template-hello-world-ng"
372+
"@nativescript/template-hello-world-ng",
370373
);
371374
assert.equal(validateProjectCallsCount, 1);
372375
assert.isTrue(createProjectCalledWithForce);
@@ -382,7 +385,7 @@ describe("Project commands tests", () => {
382385

383386
assert.deepStrictEqual(
384387
selectedTemplateName,
385-
"@nativescript/template-drawer-navigation-ts"
388+
"@nativescript/template-drawer-navigation-ts",
386389
);
387390
assert.equal(validateProjectCallsCount, 1);
388391
assert.isTrue(createProjectCalledWithForce);
@@ -398,7 +401,7 @@ describe("Project commands tests", () => {
398401

399402
assert.deepStrictEqual(
400403
selectedTemplateName,
401-
"@nativescript/template-tab-navigation"
404+
"@nativescript/template-tab-navigation",
402405
);
403406
assert.equal(validateProjectCallsCount, 1);
404407
assert.isTrue(createProjectCalledWithForce);
@@ -414,7 +417,7 @@ describe("Project commands tests", () => {
414417

415418
assert.deepStrictEqual(
416419
selectedTemplateName,
417-
"@nativescript/template-drawer-navigation-vue"
420+
"@nativescript/template-drawer-navigation-vue",
418421
);
419422
assert.equal(validateProjectCallsCount, 1);
420423
assert.isTrue(createProjectCalledWithForce);
@@ -430,7 +433,7 @@ describe("Project commands tests", () => {
430433

431434
assert.deepStrictEqual(
432435
selectedTemplateName,
433-
"@nativescript/template-blank-react"
436+
"@nativescript/template-blank-react",
434437
);
435438
assert.equal(validateProjectCallsCount, 1);
436439
assert.isTrue(createProjectCalledWithForce);
@@ -446,7 +449,7 @@ describe("Project commands tests", () => {
446449

447450
assert.deepStrictEqual(
448451
selectedTemplateName,
449-
"@nativescript/template-blank-svelte"
452+
"@nativescript/template-blank-svelte",
450453
);
451454
assert.equal(validateProjectCallsCount, 1);
452455
assert.isTrue(createProjectCalledWithForce);

0 commit comments

Comments
 (0)