Skip to content

Commit 758f088

Browse files
josephperrottkirjs
authored andcommitted
test(core): remove shelljs from core schematics tests (#64042)
Remove shelljs usage from core schematic tests and use builtins instead PR Close #64042
1 parent 9c29a40 commit 758f088

19 files changed

Lines changed: 80 additions & 104 deletions

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
"@types/selenium-webdriver": "3.0.7",
9999
"@types/selenium-webdriver4": "npm:@types/[email protected]",
100100
"@types/semver": "^7.3.4",
101-
"@types/shelljs": "^0.8.6",
102101
"@types/systemjs": "6.15.3",
103102
"@types/yargs": "^17.0.3",
104103
"angular-1.5": "npm:[email protected]",
@@ -144,7 +143,6 @@
144143
"selenium-webdriver": "3.5.0",
145144
"selenium-webdriver4": "npm:[email protected]",
146145
"semver-dsl": "^1.0.1",
147-
"shelljs": "^0.10.0",
148146
"source-map": "0.7.6",
149147
"source-map-support": "0.5.21",
150148
"systemjs": "0.18.10",

packages/compiler-cli/test/compliance/test_cases/list_golden_update_rules.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import {exec} from 'shelljs';
1+
import { spawnSync } from "child_process";
22

33
const {BUILD_WORKSPACE_DIRECTORY} = process.env;
44

5-
const rulesResult = exec(
6-
'pnpm --silent bazel query \'filter("\\.update$", kind(rule, //packages/compiler-cli/test/compliance/test_cases:*))\' --output label',
7-
{cwd: BUILD_WORKSPACE_DIRECTORY, env: process.env, silent: true});
5+
const rulesResult = spawnSync(
6+
'pnpm',
7+
['--silent', 'bazel', 'query', 'filter("\\.update$", kind(rule, //packages/compiler-cli/test/compliance/test_cases:*))', '--output=label'],
8+
{cwd: BUILD_WORKSPACE_DIRECTORY, env: process.env, encoding: 'utf-8'});
89

9-
if (rulesResult.code !== 0) {
10+
if (rulesResult.status !== 0) {
1011
throw new Error('Failed to query Bazel for the update rules:\n' + rulesResult.stderr);
1112
}
1213

13-
for (const rule of rulesResult.split('\n')) {
14+
for (const rule of rulesResult.stdout.split('\n')) {
1415
if (rule.trim() !== '') {
1516
console.log('pnpm bazel run ' + rule);
1617
}

packages/compiler-cli/test/compliance/update_all_goldens.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
*/
1010

1111
// tslint:disable:no-console
12-
import shelljs from 'shelljs';
13-
const {exec} = shelljs;
12+
import {execSync, spawnSync} from 'child_process';
1413

1514
process.stdout.write('Gathering all partial golden update targets');
1615
const queryCommand = `pnpm -s bazel query --output label "kind(_write_source_file, //packages/compiler-cli/test/compliance/test_cases:*)"`;
17-
const allUpdateTargets = exec(queryCommand, {silent: true})
16+
const allUpdateTargets = execSync(queryCommand, {encoding: 'utf-8', stdio: 'pipe'})
1817
.trim()
1918
.split('\n')
2019
.map((target) => target.trim())
@@ -33,10 +32,13 @@ process.stdout.cursorTo(0);
3332
for (const [index, target] of allUpdateTargets.entries()) {
3433
const progress = `${index + 1} / ${allUpdateTargets.length}`;
3534
process.stdout.write(`[${progress}] Running: ${target}`);
36-
const commandResult = exec(`pnpm bazel run ${target}`, {silent: true});
35+
const commandResult = spawnSync('pnpm', ['bazel', 'run', target], {
36+
stdio: 'pipe',
37+
encoding: 'utf-8',
38+
});
3739
process.stdout.clearLine();
3840
process.stdout.cursorTo(0);
39-
if (commandResult.code) {
41+
if (commandResult.status) {
4042
console.error(`[${progress}] Failed run: ${target}`);
4143
console.group();
4244
console.error(commandResult.stdout || commandResult.stderr);

packages/core/schematics/test/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ts_project(
77
deps = [
88
"//:node_modules/@angular-devkit/core",
99
"//:node_modules/@angular-devkit/schematics",
10-
"//:node_modules/@types/shelljs",
1110
"//:node_modules/tslint",
1211
"//packages/core/schematics/utils",
1312
"//packages/core/schematics/utils/tsurge",
@@ -19,7 +18,6 @@ jasmine_test(
1918
timeout = "moderate",
2019
data = [
2120
":test_lib",
22-
"//:node_modules/shelljs",
2321
"//packages/core/schematics:bundles",
2422
"//packages/core/schematics:schematics_jsons",
2523
"//packages/core/schematics/migrations/control-flow-migration:static_files",

packages/core/schematics/test/all-migrations.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
1010
import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
13+
import {rmSync} from 'node:fs';
1314
import fs from 'fs';
1415
import {resolve} from 'path';
15-
import shx from 'shelljs';
1616

1717
describe('all migrations', () => {
1818
let runner: SchematicTestRunner;
@@ -41,17 +41,17 @@ describe('all migrations', () => {
4141
);
4242
writeFile('/tsconfig.json', `{}`);
4343

44-
previousWorkingDir = shx.pwd();
44+
previousWorkingDir = process.cwd();
4545
tmpDirPath = getSystemPath(host.root);
4646

4747
// Switch into the temporary directory path. This allows us to run
4848
// the schematic against our custom unit test tree.
49-
shx.cd(tmpDirPath);
49+
process.chdir(tmpDirPath);
5050
});
5151

5252
afterEach(() => {
53-
shx.cd(previousWorkingDir);
54-
shx.rm('-r', tmpDirPath);
53+
process.chdir(previousWorkingDir);
54+
rmSync(tmpDirPath, {recursive: true});
5555
});
5656

5757
function writeFile(filePath: string, contents: string) {
@@ -103,7 +103,7 @@ describe('all migrations', () => {
103103
error = e;
104104
}
105105

106-
expect(error).toBe(null);
106+
expect(error).toBe(null, migrationName);
107107
});
108108
}
109109
});

packages/core/schematics/test/application_config_core_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
1313
import {resolve} from 'node:path';
14-
import shx from 'shelljs';
14+
import {execSync} from 'node:child_process';
1515

1616
describe('application-config migration', () => {
1717
let runner: SchematicTestRunner;
@@ -43,7 +43,7 @@ describe('application-config migration', () => {
4343
}),
4444
);
4545

46-
shx.cd(tmpDirPath);
46+
process.chdir(tmpDirPath);
4747
});
4848

4949
it('should migrate an import of ApplicationConfig', async () => {

packages/core/schematics/test/cleanup_unused_imports_migration_spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
1313
import {resolve} from 'node:path';
14-
import shx from 'shelljs';
14+
import {rmSync} from 'node:fs';
1515

1616
describe('cleanup unused imports schematic', () => {
1717
let runner: SchematicTestRunner;
@@ -45,13 +45,13 @@ describe('cleanup unused imports schematic', () => {
4545
}),
4646
);
4747

48-
previousWorkingDir = shx.pwd();
48+
previousWorkingDir = process.cwd();
4949
tmpDirPath = getSystemPath(host.root);
5050
runner.logger.subscribe((log) => logs.push(log.message));
5151

5252
// Switch into the temporary directory path. This allows us to run
5353
// the schematic against our custom unit test tree.
54-
shx.cd(tmpDirPath);
54+
process.chdir(tmpDirPath);
5555

5656
writeFile(
5757
'directives.ts',
@@ -71,8 +71,8 @@ describe('cleanup unused imports schematic', () => {
7171
});
7272

7373
afterEach(() => {
74-
shx.cd(previousWorkingDir);
75-
shx.rm('-r', tmpDirPath);
74+
process.chdir(previousWorkingDir);
75+
rmSync(tmpDirPath, {recursive: true});
7676
});
7777

7878
it('should clean up an array where some imports are not used', async () => {

packages/core/schematics/test/control_flow_migration_spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
1313
import {resolve} from 'path';
14-
import shx from 'shelljs';
14+
import {rmSync} from 'node:fs';
1515

1616
describe('control flow migration (ng update)', () => {
1717
let runner: SchematicTestRunner;
@@ -54,17 +54,17 @@ describe('control flow migration (ng update)', () => {
5454
}),
5555
);
5656

57-
previousWorkingDir = shx.pwd();
57+
previousWorkingDir = process.cwd();
5858
tmpDirPath = getSystemPath(host.root);
5959

6060
// Switch into the temporary directory path. This allows us to run
6161
// the schematic against our custom unit test tree.
62-
shx.cd(tmpDirPath);
62+
process.chdir(tmpDirPath);
6363
});
6464

6565
afterEach(() => {
66-
shx.cd(previousWorkingDir);
67-
shx.rm('-r', tmpDirPath);
66+
process.chdir(previousWorkingDir);
67+
rmSync(tmpDirPath, {recursive: true});
6868
});
6969

7070
describe('ngIf', () => {
@@ -6912,17 +6912,17 @@ describe('control flow migration (ng generate)', () => {
69126912
}),
69136913
);
69146914

6915-
previousWorkingDir = shx.pwd();
6915+
previousWorkingDir = process.cwd();
69166916
tmpDirPath = getSystemPath(host.root);
69176917

69186918
// Switch into the temporary directory path. This allows us to run
69196919
// the schematic against our custom unit test tree.
6920-
shx.cd(tmpDirPath);
6920+
process.chdir(tmpDirPath);
69216921
});
69226922

69236923
afterEach(() => {
6924-
shx.cd(previousWorkingDir);
6925-
shx.rm('-r', tmpDirPath);
6924+
process.chdir(previousWorkingDir);
6925+
rmSync(tmpDirPath, {recursive: true});
69266926
});
69276927

69286928
describe('path', () => {

packages/core/schematics/test/inject_migration_spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
1313
import {resolve} from 'node:path';
14-
import shx from 'shelljs';
14+
import {rmSync} from 'node:fs';
1515

1616
describe('inject migration', () => {
1717
let runner: SchematicTestRunner;
@@ -50,14 +50,14 @@ describe('inject migration', () => {
5050
}),
5151
);
5252

53-
previousWorkingDir = shx.pwd();
53+
previousWorkingDir = process.cwd();
5454
tmpDirPath = getSystemPath(host.root);
55-
shx.cd(tmpDirPath);
55+
process.chdir(tmpDirPath);
5656
});
5757

5858
afterEach(() => {
59-
shx.cd(previousWorkingDir);
60-
shx.rm('-r', tmpDirPath);
59+
process.chdir(previousWorkingDir);
60+
rmSync(tmpDirPath, {recursive: true});
6161
});
6262

6363
['Directive', 'Component', 'Pipe', 'NgModule'].forEach((decorator) => {

packages/core/schematics/test/output_migration_spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
1313
import {resolve} from 'node:path';
14-
import shx from 'shelljs';
14+
import {rmSync} from 'node:fs';
1515

1616
describe('output migration', () => {
1717
let runner: SchematicTestRunner;
@@ -43,14 +43,14 @@ describe('output migration', () => {
4343
}),
4444
);
4545

46-
previousWorkingDir = shx.pwd();
46+
previousWorkingDir = process.cwd();
4747
tmpDirPath = getSystemPath(host.root);
48-
shx.cd(tmpDirPath);
48+
process.chdir(tmpDirPath);
4949
});
5050

5151
afterEach(() => {
52-
shx.cd(previousWorkingDir);
53-
shx.rm('-r', tmpDirPath);
52+
process.chdir(previousWorkingDir);
53+
rmSync(tmpDirPath, {recursive: true});
5454
});
5555

5656
it('should work', async () => {

0 commit comments

Comments
 (0)