_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular-cli/tests/legacy-cli/e2e/tests/generate/class.ts_0_537
import { join } from 'path'; import { ng } from '../../utils/process'; import { expectFileToExist } from '../../utils/fs'; export default function () { const projectDir = join('src', 'app'); return ( ng('generate', 'class', 'test-class') .then(() => expectFileToExist(projectDir)) .then(() => expectFileToExist(join(projectDir, 'test-class.ts'))) .then(() => expectFileToExist(join(projectDir, 'test-class.spec.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 537, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/class.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/schematic-aliases.ts_0_351
import { ng } from '../../utils/process'; export default async function () { const schematicNameVariation = [ 'component', 'c', '@schematics/angular:component', '@schematics/angular:c', ]; for (const schematic of schematicNameVariation) { await ng('generate', schematic, 'comp-name', '--display-block', '--dry-run'); } }
{ "end_byte": 351, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/schematic-aliases.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/install-allow-scripts.ts_0_1518
import { copyAssets } from '../../utils/assets'; import { expectFileNotToExist, expectFileToExist, rimraf } from '../../utils/fs'; import { ng } from '../../utils/process'; export default async function () { // Copy test schematic into test project to ensure schematic dependencies are available await copyAssets('schematic-allow-scripts', 'schematic-allow-scripts'); // By default should not run the postinstall from the added package.json in the schematic await ng('generate', './schematic-allow-scripts:test'); await expectFileToExist('install-test/package.json'); await expectFileNotToExist('install-test/post-script-ran'); // Cleanup for next test case await rimraf('install-test'); // Should run the postinstall if the allowScripts task option is enabled // For testing purposes, this schematic exposes the task option via a schematic option await ng('generate', './schematic-allow-scripts:test', '--allow-scripts'); await expectFileToExist('install-test/package.json'); await expectFileToExist('install-test/post-script-ran'); // Cleanup for next test case await rimraf('install-test'); // Package manager configuration should take priority // The `ignoreScripts` schematic option sets the value of the `ignore-scripts` option in a test project `.npmrc` await ng('generate', './schematic-allow-scripts:test', '--allow-scripts', '--ignore-scripts'); await expectFileToExist('install-test/package.json'); await expectFileNotToExist('install-test/post-script-ran'); }
{ "end_byte": 1518, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/install-allow-scripts.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/help-output.ts_0_3738
import { join } from 'path'; import { ng, ProcessOutput } from '../../utils/process'; import { writeMultipleFiles, createDir } from '../../utils/fs'; import { updateJsonFile } from '../../utils/project'; export default function () { // setup temp collection const genRoot = join('node_modules/fake-schematics/'); return ( Promise.resolve() .then(() => createDir(genRoot)) .then(() => writeMultipleFiles({ [join(genRoot, 'package.json')]: ` { "schematics": "./collection.json" }`, [join(genRoot, 'collection.json')]: ` { "schematics": { "fake": { "factory": "./fake", "description": "Fake schematic", "schema": "./fake-schema.json" }, } }`, [join(genRoot, 'fake-schema.json')]: ` { "$id": "FakeSchema", "title": "Fake Schema", "type": "object", "required": ["a"], "properties": { "b": { "type": "string", "description": "b.", "$default": { "$source": "argv", "index": 1 } }, "a": { "type": "string", "description": "a.", "$default": { "$source": "argv", "index": 0 } }, "optC": { "type": "string", "description": "optC" }, "optA": { "type": "string", "description": "optA" }, "optB": { "type": "string", "description": "optB" } } }`, [join(genRoot, 'fake.js')]: ` function def(options) { return (host, context) => { return host; }; } exports.default = def; `, }), ) .then(() => ng('generate', 'fake-schematics:fake', '--help')) .then(({ stdout }) => { if (!/ng generate fake-schematics:fake <a> \[b\]/.test(stdout)) { throw new Error('Help signature is wrong (1).'); } if (!/opt-a[\s\S]*opt-b[\s\S]*opt-c/.test(stdout)) { throw new Error('Help signature options are incorrect.'); } }) // set up default collection. .then(() => updateJsonFile('angular.json', (json) => { json.cli = json.cli || ({} as any); json.cli.schematicCollections = ['fake-schematics']; }), ) .then(() => ng('generate', 'fake', '--help')) // verify same output .then(({ stdout }) => { if (!/ng generate fake <a> \[b\]/.test(stdout)) { throw new Error('Help signature is wrong (2).'); } if (!/opt-a[\s\S]*opt-b[\s\S]*opt-c/.test(stdout)) { throw new Error('Help signature options are incorrect.'); } }) // should print all the available schematics in a collection // when a collection has more than 1 schematic .then(() => writeMultipleFiles({ [join(genRoot, 'collection.json')]: ` { "schematics": { "fake": { "factory": "./fake", "description": "Fake schematic", "schema": "./fake-schema.json" }, "fake-two": { "factory": "./fake", "description": "Fake schematic", "schema": "./fake-schema.json" }, } }`, }), ) .then(() => ng('generate', '--help')) .then(({ stdout }) => { if (!/fake[\s\S]*fake-two/.test(stdout)) { throw new Error(`Help result is wrong, it didn't contain all the schematics.`); } }) ); }
{ "end_byte": 3738, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/help-output.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/interface.ts_0_493
import { join } from 'path'; import { ng } from '../../utils/process'; import { expectFileToExist } from '../../utils/fs'; export default function () { const interfaceDir = join('src', 'app'); return ( ng('generate', 'interface', 'test-interface', 'model') .then(() => expectFileToExist(interfaceDir)) .then(() => expectFileToExist(join(interfaceDir, 'test-interface.model.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 493, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/interface.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/help-output-no-duplicates.ts_0_545
import { ng } from '../../utils/process'; export default async function () { // Verify that there are no duplicate options const { stdout } = await ng('generate', 'component', '--help'); const firstIndex = stdout.indexOf('--prefix'); if (firstIndex < 0) { console.log(stdout); throw new Error('--prefix was not part of the help output.'); } if (firstIndex !== stdout.lastIndexOf('--prefix')) { console.log(stdout); throw new Error('--prefix first and last index were different. Possible duplicate output!'); } }
{ "end_byte": 545, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/help-output-no-duplicates.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/schematics-collections.ts_0_3257
import { join } from 'path'; import { ng } from '../../utils/process'; import { writeMultipleFiles, createDir, expectFileToExist } from '../../utils/fs'; import { updateJsonFile } from '../../utils/project'; export default async function () { // setup temp collection const genRoot = join('node_modules/fake-schematics/'); const fakeComponentSchematicDesc = 'Fake component schematic'; await createDir(genRoot); await writeMultipleFiles({ [join(genRoot, 'package.json')]: JSON.stringify({ 'schematics': './collection.json', }), [join(genRoot, 'collection.json')]: JSON.stringify({ 'schematics': { 'fake': { 'description': 'Fake schematic', 'schema': './fake-schema.json', 'factory': './fake', }, 'component': { 'description': fakeComponentSchematicDesc, 'schema': './fake-schema.json', 'factory': './fake-component', }, }, }), [join(genRoot, 'fake-schema.json')]: JSON.stringify({ '$id': 'FakeSchema', 'title': 'Fake Schema', 'type': 'object', }), [join(genRoot, 'fake.js')]: ` exports.default = function (options) { return (host, context) => { console.log('fake schematic run.'); }; } `, [join(genRoot, 'fake-component.js')]: ` exports.default = function (options) { return (host, context) => { console.log('fake component schematic run.'); }; } `, }); await updateJsonFile('angular.json', (json) => { json.cli ??= {}; json.cli.schematicCollections = ['fake-schematics', '@schematics/angular']; }); // should display schematics for all schematics const { stdout: stdout1 } = await ng('generate', '--help'); if (!stdout1.includes('ng generate component')) { throw new Error(`Didn't show schematics of '@schematics/angular'.`); } if (!stdout1.includes('ng generate fake')) { throw new Error(`Didn't show schematics of 'fake-schematics'.`); } // check registration order. Both schematics contain a component schematic verify that the first one wins. if (!stdout1.includes(fakeComponentSchematicDesc)) { throw new Error(`Didn't show fake component description.`); } // Verify execution based on ordering const { stdout: stdout2 } = await ng('generate', 'component'); if (!stdout2.includes('fake component schematic run')) { throw new Error(`stdout didn't contain 'fake component schematic run'.`); } await updateJsonFile('angular.json', (json) => { json.cli ??= {}; json.cli.schematicCollections = ['@schematics/angular', 'fake-schematics']; }); const { stdout: stdout3 } = await ng('generate', '--help'); if (!stdout3.includes('ng generate component [name]')) { throw new Error(`Didn't show component description from @schematics/angular.`); } if (stdout3.includes(fakeComponentSchematicDesc)) { throw new Error(`Shown fake component description, when it shouldn't.`); } // Verify execution based on ordering const projectDir = join('src', 'app'); const componentDir = join(projectDir, 'test-component'); await ng('generate', 'component', 'test-component'); await expectFileToExist(componentDir); }
{ "end_byte": 3257, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/schematics-collections.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/pipe/pipe-basic.ts_0_582
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; export default function () { // Create the pipe in the same directory. const pipeDir = join('src', 'app'); return ( ng('generate', 'pipe', 'test-pipe') .then(() => expectFileToExist(pipeDir)) .then(() => expectFileToExist(join(pipeDir, 'test-pipe.pipe.ts'))) .then(() => expectFileToExist(join(pipeDir, 'test-pipe.pipe.spec.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 582, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/pipe/pipe-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/config/type-karma.ts_0_254
import { ng } from '../../../utils/process'; import { useCIChrome } from '../../../utils/project'; export default async function () { await ng('generate', 'config', 'karma'); await useCIChrome('test-project'); await ng('test', '--watch=false'); }
{ "end_byte": 254, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/config/type-karma.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/config/type-browserslist.ts_0_154
import { ng } from '../../../utils/process'; export default async function () { await ng('generate', 'config', 'browserslist'); await ng('build'); }
{ "end_byte": 154, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/config/type-browserslist.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/module/module-import.ts_0_2904
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToMatch } from '../../../utils/fs'; export default async function () { const projectName = 'test-project-two'; await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); await ng('generate', 'module', 'sub', '--project', projectName); await ng('generate', 'module', 'sub/deep', '--project', projectName); const projectAppDir = `projects/${projectName}/src/app`; const modulePath = join(projectAppDir, 'app.module.ts'); const subModulePath = join(projectAppDir, 'sub/sub.module.ts'); const deepSubModulePath = join(projectAppDir, 'sub/deep/deep.module.ts'); await ng('generate', 'module', 'test1', '--module', 'app.module.ts', '--project', projectName); await expectFileToMatch(modulePath, `import { Test1Module } from './test1/test1.module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test1Module.*?\]/s); await ng('generate', 'module', 'test2', '--module', 'app.module', '--project', projectName); await expectFileToMatch(modulePath, `import { Test2Module } from './test2/test2.module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test2Module.*?\]/s); await ng('generate', 'module', 'test3', '--module', 'app', '--project', projectName); await expectFileToMatch(modulePath, `import { Test3Module } from './test3/test3.module'`); await expectFileToMatch(modulePath, /imports: \[.*?Test3Module.*?\]/s); await ng('generate', 'module', 'test4', '--routing', '--module', 'app', '--project', projectName); await expectFileToMatch(modulePath, /imports: \[.*?Test4Module.*?\]/s); await expectFileToMatch( join(projectAppDir, 'test4/test4.module.ts'), `import { Test4RoutingModule } from './test4-routing.module'`, ); await expectFileToMatch( join(projectAppDir, 'test4/test4.module.ts'), /imports: \[.*?Test4RoutingModule.*?\]/s, ); await ng('generate', 'module', 'test5', '--module', 'sub', '--project', projectName); await expectFileToMatch(subModulePath, `import { Test5Module } from '../test5/test5.module'`); await expectFileToMatch(subModulePath, /imports: \[.*?Test5Module.*?\]/s); await ng('generate', 'module', 'test6', '--module', 'sub/deep', '--project', projectName); await expectFileToMatch( deepSubModulePath, `import { Test6Module } from '../../test6/test6.module'`, ); await expectFileToMatch(deepSubModulePath, /imports: \[.*?Test6Module.*?\]/s); // E2E_DISABLE: temporarily disable pending investigation // await process.chdir(join(root, 'src', 'app'))) // await ng('generate', 'module', 'test7', '--module', 'app.module.ts')) // await process.chdir('..')) // await expectFileToMatch(modulePath, // /import { Test7Module } from '.\/test7\/test7.module'/)) // await expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m)); }
{ "end_byte": 2904, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/module/module-import.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts_0_1096
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; import { expectToFail } from '../../../utils/utils'; import { useCIChrome, useCIDefaults } from '../../../utils/project'; export default async function () { const projectName = 'test-project-two'; const moduleDir = `projects/${projectName}/src/app/test`; await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); await useCIDefaults(projectName); await useCIChrome(projectName, 'projects/test-project-two'); await ng('generate', 'module', 'test', '--project', projectName); await expectFileToExist(moduleDir); await expectFileToExist(join(moduleDir, 'test.module.ts')); await expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))); await expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))); await expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'); // Try to run the unit tests. await ng('test', projectName, '--watch=false'); }
{ "end_byte": 1096, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/module/module-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts_0_1093
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; import { expectToFail } from '../../../utils/utils'; import { useCIChrome, useCIDefaults } from '../../../utils/project'; export default async function () { const projectName = 'test-project-two'; await ng('generate', 'application', projectName, '--no-standalone', '--skip-install'); await useCIDefaults(projectName); await useCIChrome(projectName, 'projects/test-project-two'); const testPath = join(process.cwd(), `projects/${projectName}/src/app`); process.chdir(testPath); await ng('generate', 'module', 'sub-dir/child', '--routing'); await expectFileToExist(join(testPath, 'sub-dir/child')); await expectFileToExist(join(testPath, 'sub-dir/child', 'child.module.ts')); await expectFileToExist(join(testPath, 'sub-dir/child', 'child-routing.module.ts')); await expectToFail(() => expectFileToExist(join(testPath, 'sub-dir/child', 'child.spec.ts'))); // Try to run the unit tests. await ng('test', projectName, '--watch=false'); }
{ "end_byte": 1093, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/module/module-routing-child-folder.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-inline-template.ts_0_1240
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; import { updateJsonFile } from '../../../utils/project'; import { expectToFail } from '../../../utils/utils'; // tslint:disable:max-line-length export default function () { const componentDir = join('src', 'app', 'test-component'); return ( Promise.resolve() .then(() => updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].schematics = { '@schematics/angular:component': { inlineTemplate: true }, }; }), ) .then(() => ng('generate', 'component', 'test-component')) .then(() => expectFileToExist(componentDir)) .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) .then(() => expectToFail(() => expectFileToExist(join(componentDir, 'test-component.component.html'))), ) .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 1240, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-inline-template.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-child-dir.ts_0_1415
import { join } from 'path'; import { ng } from '../../../utils/process'; import { createDir, expectFileToExist, rimraf } from '../../../utils/fs'; export default async function () { const currentDirectory = process.cwd(); const childDirectory = join('src', 'app', 'sub-dir'); try { // Create and enter a child directory inside the project await createDir(childDirectory); process.chdir(childDirectory); // Generate a component inside the child directory await ng('generate', 'component', 'test-component'); // Move back to the root of the workspacee process.chdir(currentDirectory); // Ensure component is created in the correct location relative to the workspace root const componentDirectory = join(childDirectory, 'test-component'); await expectFileToExist(join(componentDirectory, 'test-component.component.ts')); await expectFileToExist(join(componentDirectory, 'test-component.component.spec.ts')); await expectFileToExist(join(componentDirectory, 'test-component.component.html')); await expectFileToExist(join(componentDirectory, 'test-component.component.css')); // Ensure unit test execute and pass await ng('test', '--watch=false'); } finally { // Windows CI may fail to clean up the created directory // Resolves: "Error: Running "cmd.exe /c git clean -df" returned error code 1" await rimraf(childDirectory); } }
{ "end_byte": 1415, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-child-dir.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-not-flat.ts_0_1109
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; import { updateJsonFile } from '../../../utils/project'; export default function () { const componentDir = join('src', 'app', 'test-component'); return ( Promise.resolve() .then(() => updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].schematics = { '@schematics/angular:component': { flat: false }, }; }), ) .then(() => ng('generate', 'component', 'test-component')) .then(() => expectFileToExist(componentDir)) .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 1109, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-not-flat.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-flat.ts_0_1053
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; import { updateJsonFile } from '../../../utils/project'; export default function () { const appDir = join('src', 'app'); return ( Promise.resolve() .then(() => updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].schematics = { '@schematics/angular:component': { flat: true }, }; }), ) .then(() => ng('generate', 'component', 'test-component')) .then(() => expectFileToExist(appDir)) .then(() => expectFileToExist(join(appDir, 'test-component.component.ts'))) .then(() => expectFileToExist(join(appDir, 'test-component.component.spec.ts'))) .then(() => expectFileToExist(join(appDir, 'test-component.component.html'))) .then(() => expectFileToExist(join(appDir, 'test-component.component.css'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 1053, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-flat.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-prefix.ts_0_1012
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToMatch } from '../../../utils/fs'; import { updateJsonFile } from '../../../utils/project'; export default function () { const testCompDir = join('src', 'app', 'test-component'); const aliasCompDir = join('src', 'app', 'alias'); return ( Promise.resolve() .then(() => updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].schematics = { '@schematics/angular:component': { prefix: 'pre' }, }; }), ) .then(() => ng('generate', 'component', 'test-component')) .then(() => expectFileToMatch(join(testCompDir, 'test-component.component.ts'), /selector: 'pre-/), ) .then(() => ng('g', 'c', 'alias')) .then(() => expectFileToMatch(join(aliasCompDir, 'alias.component.ts'), /selector: 'pre-/)) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 1012, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-prefix.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-path-case.ts_0_1808
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, rimraf } from '../../../utils/fs'; export default async function () { const upperDirs = join('non', 'existing', 'dir'); const rootDir = join('src', 'app', upperDirs); const componentDirectory = join(rootDir, 'test-component'); const componentTwoDirectory = join(rootDir, 'test-component-two'); try { // Generate a component await ng('generate', 'component', `${upperDirs}/test-component`); // Ensure component is created in the correct location relative to the workspace root await expectFileToExist(join(componentDirectory, 'test-component.component.ts')); await expectFileToExist(join(componentDirectory, 'test-component.component.spec.ts')); await expectFileToExist(join(componentDirectory, 'test-component.component.html')); await expectFileToExist(join(componentDirectory, 'test-component.component.css')); // Generate another component await ng('generate', 'component', `${upperDirs}/Test-Component-Two`); // Ensure component is created in the correct location relative to the workspace root await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.ts')); await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.spec.ts')); await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.html')); await expectFileToExist(join(componentTwoDirectory, 'test-component-two.component.css')); // Ensure unit test execute and pass await ng('test', '--watch=false'); } finally { // Windows CI may fail to clean up the created directory // Resolves: "Error: Running "cmd.exe /c git clean -df" returned error code 1" await rimraf(rootDir); } }
{ "end_byte": 1808, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-path-case.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts_0_823
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; export default function () { const projectDir = join('src', 'app'); const componentDir = join(projectDir, 'test-component'); return ( ng('generate', 'component', 'test-component') .then(() => expectFileToExist(componentDir)) .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 823, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/component/component-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/library/library-basic.ts_0_356
import { ng } from '../../../utils/process'; import { useCIChrome } from '../../../utils/project'; export default async function () { await ng('generate', 'library', 'lib-ngmodule', '--no-standalone'); await useCIChrome('lib-ngmodule', 'projects/lib-ngmodule'); await ng('test', 'lib-ngmodule', '--no-watch'); await ng('build', 'lib-ngmodule'); }
{ "end_byte": 356, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/library/library-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/library/library-standalone.ts_0_363
import { ng } from '../../../utils/process'; import { useCIChrome } from '../../../utils/project'; export default async function () { await ng('generate', 'library', 'lib-standalone', '--standalone'); await useCIChrome('lib-standalone', 'projects/lib-standalone'); await ng('test', 'lib-standalone', '--no-watch'); await ng('build', 'lib-standalone'); }
{ "end_byte": 363, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/library/library-standalone.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/directive/directive-prefix.ts_0_1853
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToMatch } from '../../../utils/fs'; import { updateJsonFile, useCIChrome, useCIDefaults } from '../../../utils/project'; export default function () { const directiveDir = join('src', 'app'); return ( Promise.resolve() .then(() => updateJsonFile('angular.json', (configJson) => { configJson.schematics = { '@schematics/angular:directive': { prefix: 'preW' }, }; }), ) .then(() => ng('generate', 'directive', 'test2-directive')) .then(() => expectFileToMatch(join(directiveDir, 'test2-directive.directive.ts'), /selector: '\[preW/), ) .then(() => ng('generate', 'application', 'app-two', '--skip-install')) .then(() => useCIDefaults('app-two')) .then(() => useCIChrome('app-two', './projects/app-two')) .then(() => updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].schematics = { '@schematics/angular:directive': { prefix: 'preP' }, }; }), ) .then(() => process.chdir('projects/app-two')) .then(() => ng('generate', 'directive', '--skip-import', 'test3-directive')) .then(() => process.chdir('../..')) .then(() => expectFileToMatch( join('projects', 'app-two', 'test3-directive.directive.ts'), /selector: '\[preW/, ), ) .then(() => process.chdir('src/app')) .then(() => ng('generate', 'directive', 'test-directive')) .then(() => process.chdir('../..')) .then(() => expectFileToMatch(join(directiveDir, 'test-directive.directive.ts'), /selector: '\[preP/), ) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 1853, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/directive/directive-prefix.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/directive/directive-basic.ts_0_535
import { ng } from '../../../utils/process'; import { join } from 'path'; import { expectFileToExist } from '../../../utils/fs'; export default function () { const directiveDir = join('src', 'app'); return ( ng('generate', 'directive', 'test-directive') .then(() => expectFileToExist(join(directiveDir, 'test-directive.directive.ts'))) .then(() => expectFileToExist(join(directiveDir, 'test-directive.directive.spec.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 535, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/directive/directive-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/application/application-zoneless.ts_0_647
import { ng } from '../../../utils/process'; import { useCIChrome } from '../../../utils/project'; export default async function () { await ng('generate', 'app', 'standalone', '--experimental-zoneless', '--standalone'); await useCIChrome('standalone', 'projects/standalone'); await ng('test', 'standalone', '--watch=false'); await ng('build', 'standalone'); await ng( 'generate', 'app', 'ngmodules', '--experimental-zoneless', '--no-standalone', '--skip-install', ); await useCIChrome('ngmodules', 'projects/ngmodules'); await ng('test', 'ngmodules', '--watch=false'); await ng('build', 'ngmodules'); }
{ "end_byte": 647, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/application/application-zoneless.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/application/application-basic.ts_0_405
import { expectFileToMatch } from '../../../utils/fs'; import { ng } from '../../../utils/process'; import { useCIChrome } from '../../../utils/project'; export default function () { return ng('generate', 'application', 'app2') .then(() => expectFileToMatch('angular.json', /\"app2\":/)) .then(() => useCIChrome('app2', 'projects/app2')) .then(() => ng('test', 'app2', '--watch=false')); }
{ "end_byte": 405, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/application/application-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/service/service-basic.ts_0_605
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; export default function () { // Does not create a sub directory. const serviceDir = join('src', 'app'); return ( ng('generate', 'service', 'test-service') .then(() => expectFileToExist(serviceDir)) .then(() => expectFileToExist(join(serviceDir, 'test-service.service.ts'))) .then(() => expectFileToExist(join(serviceDir, 'test-service.service.spec.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 605, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/service/service-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts_0_647
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; export default async function () { // Does not create a sub directory. const guardDir = join('src', 'app'); await ng('generate', 'guard', 'test-guard'); await expectFileToExist(guardDir); await expectFileToExist(join(guardDir, 'test-guard.guard.ts')); await expectFileToMatch( join(guardDir, 'test-guard.guard.ts'), /export const testGuardGuard: CanActivateFn/, ); await expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts')); await ng('test', '--watch=false'); }
{ "end_byte": 647, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/guard/guard-multiple-implements.ts_0_828
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; export default async function () { // Does not create a sub directory. const guardDir = join('src', 'app'); // multiple implements are only supported in (deprecated) class-based guards await ng( 'generate', 'guard', 'multiple', '--implements=CanActivate', '--implements=CanDeactivate', '--no-functional', ); await expectFileToExist(guardDir); await expectFileToExist(join(guardDir, 'multiple.guard.ts')); await expectFileToMatch( join(guardDir, 'multiple.guard.ts'), /implements CanActivate, CanDeactivate<unknown>/, ); await expectFileToExist(join(guardDir, 'multiple.guard.spec.ts')); await ng('test', '--watch=false'); }
{ "end_byte": 828, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/guard/guard-multiple-implements.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts_0_630
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist, expectFileToMatch } from '../../../utils/fs'; export default async function () { // Does not create a sub directory. const guardDir = join('src', 'app'); await ng('generate', 'guard', 'match', '--implements=CanMatch'); await expectFileToExist(guardDir); await expectFileToExist(join(guardDir, 'match.guard.ts')); await expectFileToMatch(join(guardDir, 'match.guard.ts'), /export const matchGuard: CanMatch/); await expectFileToExist(join(guardDir, 'match.guard.spec.ts')); await ng('test', '--watch=false'); }
{ "end_byte": 630, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts" }
angular-cli/tests/legacy-cli/e2e/tests/generate/interceptor/interceptor-basic.ts_0_645
import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToExist } from '../../../utils/fs'; export default function () { // Does not create a sub directory. const interceptorDir = join('src', 'app'); return ( ng('generate', 'interceptor', 'test-interceptor') .then(() => expectFileToExist(interceptorDir)) .then(() => expectFileToExist(join(interceptorDir, 'test-interceptor.interceptor.ts'))) .then(() => expectFileToExist(join(interceptorDir, 'test-interceptor.interceptor.spec.ts'))) // Try to run the unit tests. .then(() => ng('test', '--watch=false')) ); }
{ "end_byte": 645, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/generate/interceptor/interceptor-basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts_0_924
import { join } from 'node:path'; import { getGlobalVariable } from '../../utils/env'; import { exec, silentNpm } from '../../utils/process'; import { rimraf } from '../../utils/fs'; export default async function () { // setup const argv = getGlobalVariable('argv'); if (argv.noglobal) { return; } await silentNpm('install', '-g', '@angular-devkit/schematics-cli'); await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics'); const startCwd = process.cwd(); const schematicPath = join(startCwd, 'test-schematic'); try { // create schematic await exec('schematics', 'blank', '--name', 'test-schematic'); process.chdir(schematicPath); await silentNpm('test'); } finally { // restore path process.chdir(startCwd); await Promise.all([ rimraf(schematicPath), silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'), ]); } }
{ "end_byte": 924, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts" }
angular-cli/tests/legacy-cli/e2e/tests/schematics_cli/schematic-test.ts_0_928
import { join } from 'node:path'; import { getGlobalVariable } from '../../utils/env'; import { exec, silentNpm } from '../../utils/process'; import { rimraf } from '../../utils/fs'; export default async function () { // setup const argv = getGlobalVariable('argv'); if (argv.noglobal) { return; } await silentNpm('install', '-g', '@angular-devkit/schematics-cli'); await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics'); const startCwd = process.cwd(); const schematicPath = join(startCwd, 'test-schematic'); try { // create schematic await exec('schematics', 'schematic', '--name', 'test-schematic'); process.chdir(schematicPath); await silentNpm('test'); } finally { // restore path process.chdir(startCwd); await Promise.all([ rimraf(schematicPath), silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'), ]); } }
{ "end_byte": 928, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/schematics_cli/schematic-test.ts" }
angular-cli/tests/legacy-cli/e2e/tests/schematics_cli/basic.ts_0_1080
import { join } from 'node:path'; import { getGlobalVariable } from '../../utils/env'; import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process'; import { rimraf } from '../../utils/fs'; export default async function () { // setup const argv = getGlobalVariable('argv'); if (argv.noglobal) { return; } await silentNpm('install', '-g', '@angular-devkit/schematics-cli'); await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics'); const startCwd = process.cwd(); const schematicPath = join(startCwd, 'test-schematic'); try { // create blank schematic await exec('schematics', 'schematic', '--name', 'test-schematic'); process.chdir(join(startCwd, 'test-schematic')); await execAndWaitForOutputToMatch( 'schematics', ['.:', '--list-schematics'], /my-full-schematic/, ); } finally { // restore path process.chdir(startCwd); await Promise.all([ rimraf(schematicPath), silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'), ]); } }
{ "end_byte": 1080, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/schematics_cli/basic.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/unknown-configuration.ts_0_388
import { ng } from '../../utils/process'; export default async function () { try { await ng('build', '--configuration', 'invalid'); throw new Error('should have failed.'); } catch (error) { if ( !( error instanceof Error && error.message.includes(`Configuration 'invalid' is not set in the workspace`) ) ) { throw error; } } }
{ "end_byte": 388, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/unknown-configuration.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/run-configuration-option.ts_0_822
import { silentNg } from '../../utils/process'; import { expectToFail } from '../../utils/utils'; export default async function () { const errorMatch = `Provide the configuration as part of the target 'ng run test-project:build:production`; { const { message } = await expectToFail(() => silentNg('run', 'test-project:build:development', '--configuration=production'), ); if (!message.includes(errorMatch)) { throw new Error(`Expected error to include '${errorMatch}' but didn't.\n\n${message}`); } } { const { message } = await expectToFail(() => silentNg('run', 'test-project:build', '--configuration=production'), ); if (!message.includes(errorMatch)) { throw new Error(`Expected error to include '${errorMatch}' but didn't.\n\n${message}`); } } }
{ "end_byte": 822, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/run-configuration-option.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/project-cannot-be-determined-by-cwd.ts_0_1391
import { join } from 'path'; import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; import { expectToFail } from '../../utils/utils'; export default async function () { const errorMessage = 'Cannot determine project for command.\n' + 'This is a multi-project workspace and more than one project supports this command.'; // Delete root project await updateJsonFile('angular.json', (workspaceJson) => { delete workspaceJson.projects['test-project']; }); await ng('generate', 'app', 'second-app', '--skip-install'); await ng('generate', 'app', 'third-app', '--skip-install'); const startCwd = process.cwd(); try { const { message } = await expectToFail(() => ng('build')); if (!message.includes(errorMessage)) { throw new Error(`Expected build to fail with: '${errorMessage}'.`); } // Help should still work await execAndWaitForOutputToMatch('ng', ['build', '--help'], /--configuration/); // Yargs allows positional args to be passed as flags. Verify that in this case the project can be determined. await ng('build', '--project=third-app', '--configuration=development'); process.chdir(join(startCwd, 'projects/second-app')); await ng('build', '--configuration=development'); } finally { // Restore path process.chdir(startCwd); } }
{ "end_byte": 1391, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/project-cannot-be-determined-by-cwd.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts_0_525
import { execAndWaitForOutputToMatch } from '../../utils/process'; export default async function () { const currentDirectory = process.cwd(); try { process.chdir('..'); // The below is a way to validate that the `--collection` option is being considered. await execAndWaitForOutputToMatch( 'ng', ['new', '--collection', 'invalid-schematic'], /Collection "invalid-schematic" cannot be resolved/, ); } finally { // Change directory back process.chdir(currentDirectory); } }
{ "end_byte": 525, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/builder-project-by-cwd.ts_0_699
import { join } from 'path'; import { expectFileToExist } from '../../utils/fs'; import { ng } from '../../utils/process'; export default async function () { await ng('generate', 'app', 'second-app', '--skip-install'); await ng('generate', 'app', 'third-app', '--skip-install'); const startCwd = process.cwd(); try { // When no project is provided it should favor the project that is located in the current working directory. process.chdir(join(startCwd, 'projects/second-app')); await ng('build', '--configuration=development'); process.chdir(startCwd); await expectFileToExist('dist/second-app'); } finally { // restore path process.chdir(startCwd); } }
{ "end_byte": 699, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/builder-project-by-cwd.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/unknown-option.ts_0_571
import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; import { expectToFail } from '../../utils/utils'; export default async function () { await expectToFail(() => ng('build', '--notanoption')); await execAndWaitForOutputToMatch( 'ng', ['build', '--notanoption'], /Unknown argument: notanoption/, ); const ngGenerateArgs = ['generate', 'component', 'component-name', '--notanoption']; await expectToFail(() => ng(...ngGenerateArgs)); await execAndWaitForOutputToMatch('ng', ngGenerateArgs, /Unknown argument: notanoption/); }
{ "end_byte": 571, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/unknown-option.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/additional-properties.ts_0_1308
import { createDir, rimraf, writeMultipleFiles } from '../../utils/fs'; import { execAndWaitForOutputToMatch } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { await createDir('example-builder'); await writeMultipleFiles({ 'example-builder/package.json': '{ "builders": "./builders.json" }', 'example-builder/schema.json': '{ "$schema": "http://json-schema.org/draft-07/schema", "type": "object", "additionalProperties": true }', 'example-builder/builders.json': '{ "$schema": "@angular-devkit/architect/src/builders-schema.json", "builders": { "example": { "implementation": "./example", "schema": "./schema.json" } } }', 'example-builder/example.js': 'module.exports.default = require("@angular-devkit/architect").createBuilder((options) => { console.log(options); return { success: true }; });', }); await updateJsonFile('angular.json', (json) => { const appArchitect = json.projects['test-project'].architect; appArchitect.example = { builder: './example-builder:example', }; }); await execAndWaitForOutputToMatch( 'ng', ['run', 'test-project:example', '--additional', 'property'], /Unknown argument: additional/, ); await rimraf('example-builder'); }
{ "end_byte": 1308, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/additional-properties.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/builder-not-found.ts_0_1457
import { moveFile } from '../../utils/fs'; import { getActivePackageManager, installPackage, uninstallPackage } from '../../utils/packages'; import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; import { expectToFail } from '../../utils/utils'; export default async function () { try { await uninstallPackage('@angular-devkit/build-angular'); await expectToFail(() => ng('build')); await execAndWaitForOutputToMatch( 'ng', ['build'], /Could not find the '@angular-devkit\/build-angular:browser' builder's node package\./, ); await expectToFail(() => execAndWaitForOutputToMatch( 'ng', ['build'], new RegExp( `Node packages may not be installed\\. Try installing with '${getActivePackageManager()} install'\\.`, ), ), ); await moveFile('node_modules', 'temp_node_modules'); await expectToFail(() => ng('build')); await execAndWaitForOutputToMatch( 'ng', ['build'], /Could not find the '@angular-devkit\/build-angular:browser' builder's node package\./, ); await execAndWaitForOutputToMatch( 'ng', ['build'], new RegExp( `Node packages may not be installed\\. Try installing with '${getActivePackageManager()} install'\\.`, ), ); } finally { await moveFile('temp_node_modules', 'node_modules'); await installPackage('@angular-devkit/build-angular'); } }
{ "end_byte": 1457, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/builder-not-found.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/cache/cache-enable-disable.ts_0_489
import { readFile } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('cache', 'enable'); if (JSON.parse(await readFile('angular.json')).cli.cache.enabled !== true) { throw new Error(`Expected 'cli.cache.enable' to be true.`); } await ng('cache', 'disable'); if (JSON.parse(await readFile('angular.json')).cli.cache.enabled !== false) { throw new Error(`Expected 'cli.cache.enable' to be false.`); } }
{ "end_byte": 489, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/cache/cache-enable-disable.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/cache/cache-info.ts_0_2517
import { execAndWaitForOutputToMatch } from '../../../utils/process'; import { updateJsonFile } from '../../../utils/project'; export default async function () { const originalCIValue = process.env['CI']; try { // Should be enabled by default for local builds. await configureTest('0' /** envCI */); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: enabled/, ); // Should be disabled by default for CI builds. await configureTest('1' /** envCI */, { enabled: true }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: disabled/, ); // Should be enabled by when environment is local and env is not CI. await configureTest('0' /** envCI */, { environment: 'local' }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: enabled/, ); // Should be disabled by when environment is local and env is CI. await configureTest('1' /** envCI */, { environment: 'local' }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: disabled/, ); // Effective status should be enabled when 'environment' is set to 'all' or 'ci'. await configureTest('1' /** envCI */, { environment: 'all' }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: enabled/, ); // Effective status should be enabled when 'environment' is set to 'ci' and run is in ci await configureTest('1' /** envCI */, { environment: 'ci' }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: enabled/, ); // Effective status should be disabled when 'enabled' is set to false await configureTest('1' /** envCI */, { environment: 'all', enabled: false }); await execAndWaitForOutputToMatch( 'ng', ['cache', 'info'], /Effective status on current machine: disabled/, ); } finally { process.env['CI'] = originalCIValue; } } async function configureTest( envCI: '1' | '0', cacheOptions?: { environment?: 'ci' | 'local' | 'all'; enabled?: boolean; }, ): Promise<void> { process.env['CI'] = envCI; await updateJsonFile('angular.json', (config) => { config.cli ??= {}; config.cli.cache = cacheOptions; }); }
{ "end_byte": 2517, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/cache/cache-info.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/cache/cache-clean.ts_0_349
import { createDir, expectFileNotToExist, expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { const cachePath = '.angular/cache'; await createDir(cachePath); await expectFileToExist(cachePath); await ng('cache', 'clean'); await expectFileNotToExist(cachePath); }
{ "end_byte": 349, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/cache/cache-clean.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-set-serve-port.ts_0_319
import { expectFileToMatch } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default function () { return Promise.resolve() .then(() => ng('config', 'projects.test-project.architect.serve.options.port', '1234')) .then(() => expectFileToMatch('angular.json', /"port": 1234/)); }
{ "end_byte": 319, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-set-serve-port.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-set-enum-check.ts_0_504
import { ng } from '../../../utils/process'; export default async function () { // These tests require schema querying capabilities // .then(() => expectToFail( // () => ng('config', 'schematics.@schematics/angular.component.aaa', 'bbb')), // ) // .then(() => expectToFail(() => ng( // 'config', // 'schematics.@schematics/angular.component.viewEncapsulation', // 'bbb', // ))) await ng('config', 'schematics.@schematics/angular.component.viewEncapsulation', 'Emulated'); }
{ "end_byte": 504, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-set-enum-check.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-set-prefix.ts_0_608
import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default function () { return Promise.resolve() .then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.prefix'))) .then(() => ng('config', 'schematics.@schematics/angular.component.prefix', 'new-prefix')) .then(() => ng('config', 'schematics.@schematics/angular.component.prefix')) .then(({ stdout }) => { if (!stdout.match(/new-prefix/)) { throw new Error(`Expected "new-prefix", received "${JSON.stringify(stdout)}".`); } }); }
{ "end_byte": 608, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-set-prefix.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-global.ts_0_1685
import { homedir } from 'os'; import * as path from 'path'; import { deleteFile, expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { await expectToFail(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'), ); await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false'); let output = await ng( 'config', '--global', 'schematics.@schematics/angular.component.inlineStyle', ); if (!output.stdout.match(/false\n?/)) { throw new Error(`Expected "false", received "${JSON.stringify(output.stdout)}".`); } // This test requires schema querying capabilities // .then(() => expectToFail(() => { // return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN'); // })) const cwd = process.cwd(); process.chdir('/'); try { await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true'); } finally { process.chdir(cwd); } output = await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'); if (!output.stdout.match(/true\n?/)) { throw new Error(`Expected "true", received "${JSON.stringify(output.stdout)}".`); } await expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true')); await ng('config', '--global', 'cli.warnings.versionMismatch', 'false'); await expectFileToExist(path.join(homedir(), '.angular-config.json')); await deleteFile(path.join(homedir(), '.angular-config.json')); }
{ "end_byte": 1685, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-global.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-set.ts_0_1648
import { ng, silentNg } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { let ngError: Error; ngError = await expectToFail(() => silentNg('config', 'cli.warnings.zzzz', 'true')); if ( !ngError.message.includes( 'Data path "/cli/warnings" must NOT have additional properties(zzzz).', ) ) { throw new Error('Should have failed with must NOT have additional properties(zzzz).'); } ngError = await expectToFail(() => silentNg('config', 'cli.warnings.zzzz')); if (!ngError.message.includes('Value cannot be found.')) { throw new Error('Should have failed with Value cannot be found.'); } await ng('config', 'cli.warnings.versionMismatch', 'false'); const { stdout } = await ng('config', 'cli.warnings.versionMismatch'); if (!stdout.includes('false')) { throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`); } await ng('config', 'cli.packageManager', 'yarn'); const { stdout: stdout2 } = await ng('config', 'cli.packageManager'); if (!stdout2.includes('yarn')) { throw new Error(`Expected "yarn", received "${JSON.stringify(stdout2)}".`); } await ng('config', 'schematics', '{"@schematics/angular:component":{"style": "scss"}}'); const { stdout: stdout3 } = await ng('config', 'schematics.@schematics/angular:component.style'); if (!stdout3.includes('scss')) { throw new Error(`Expected "scss", received "${JSON.stringify(stdout3)}".`); } await ng('config', 'schematics'); await ng('config', 'schematics', 'undefined'); await expectToFail(() => ng('config', 'schematics')); }
{ "end_byte": 1648, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-set.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-get.ts_0_1735
import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { await expectToFail(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle')); await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'); const { stdout } = await ng('config', 'schematics.@schematics/angular.component.inlineStyle'); if (!stdout.match(/false\n?/)) { throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`); } await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'true'); const { stdout: stdout1 } = await ng( 'config', 'schematics.@schematics/angular.component.inlineStyle', ); if (!stdout1.match(/true\n?/)) { throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`); } await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'); const { stdout: stdout2 } = await ng( 'config', `projects.test-project.architect.build.options.assets[0]`, ); if (!stdout2.includes('"input": "public"')) { throw new Error(`Expected "input": "public", received "${JSON.stringify(stdout)}".`); } const { stdout: stdout3 } = await ng( 'config', `projects["test-project"].architect.build.options.assets[0]`, ); if (!stdout3.includes('"input": "public"')) { throw new Error(`Expected "input": "public", received "${JSON.stringify(stdout)}".`); } // should print all config when no positional args are provided. const { stdout: stdout4 } = await ng('config'); if (!stdout4.includes('$schema')) { throw new Error(`Expected to contain "$schema", received "${JSON.stringify(stdout)}".`); } }
{ "end_byte": 1735, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-get.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/config/config-global-validation.ts_0_1881
import { homedir } from 'os'; import * as path from 'path'; import { deleteFile, expectFileToExist } from '../../../utils/fs'; import { ng, silentNg } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { let ngError: Error; ngError = await expectToFail(() => silentNg('config', 'cli.completion.prompted', 'true')); if ( !ngError.message.includes('Data path "/cli" must NOT have additional properties(completion).') ) { throw new Error('Should have failed with must NOT have additional properties(completion).'); } ngError = await expectToFail(() => silentNg('config', '--global', 'cli.completion.invalid', 'true'), ); if ( !ngError.message.includes( 'Data path "/cli/completion" must NOT have additional properties(invalid).', ) ) { throw new Error('Should have failed with must NOT have additional properties(invalid).'); } ngError = await expectToFail(() => silentNg('config', '--global', 'cli.cache.enabled', 'true')); if (!ngError.message.includes('Data path "/cli" must NOT have additional properties(cache).')) { throw new Error('Should have failed with must NOT have additional properties(cache).'); } ngError = await expectToFail(() => silentNg('config', 'cli.completion.prompted')); if (!ngError.message.includes('Value cannot be found.')) { throw new Error('Should have failed with Value cannot be found.'); } await ng('config', '--global', 'cli.completion.prompted', 'true'); const { stdout } = await silentNg('config', '--global', 'cli.completion.prompted'); if (!stdout.includes('true')) { throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`); } await expectFileToExist(path.join(homedir(), '.angular-config.json')); await deleteFile(path.join(homedir(), '.angular-config.json')); }
{ "end_byte": 1881, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/config/config-global-validation.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion-script.ts_0_1795
import { exec, execAndWaitForOutputToMatch } from '../../../utils/process'; export default async function () { // ng build await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'b', ''], /test-project/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'build', ''], /test-project/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'build', '--a'], /--aot/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'build', '--configuration'], /production/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'b', '--configuration'], /production/, ); // ng run await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'run', ''], /test-project\\:build\\:development/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'run', ''], /test-project\\:build/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'run', ''], /test-project\\:test/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'run', 'test-project:build'], /test-project\\:build\\:development/, ); await execAndWaitForOutputToMatch( 'ng', ['--get-yargs-completions', 'ng', 'run', 'test-project:'], /test-project\\:test/, ); const { stdout: noServeStdout } = await exec( 'ng', '--get-yargs-completions', 'ng', 'run', 'test-project:build', ); if (noServeStdout.includes(':serve')) { throw new Error( `':serve' should not have been listed as a completion option.\nSTDOUT:\n${noServeStdout}`, ); } }
{ "end_byte": 1795, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion-script.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts_0_1002
import { promises as fs } from 'fs'; import * as path from 'path'; import { env } from 'process'; import { getGlobalVariable } from '../../../utils/env'; import { mockHome } from '../../../utils/utils'; import { execAndCaptureError, execAndWaitForOutputToMatch, execWithEnv, silentNpm, } from '../../../utils/process'; const AUTOCOMPLETION_PROMPT = /Would you like to enable autocompletion\?/; const DEFAULT_ENV = Object.freeze({ ...env, // Shell should be mocked for each test that cares about it. SHELL: '/bin/bash', // Even if the actual test process is run on CI, we're testing user flows which aren't on CI. CI: undefined, // Tests run on CI technically don't have a TTY, but the autocompletion prompt requires it, so we // force a TTY by default. NG_FORCE_TTY: '1', // Analytics wants to prompt for a first command as well, but we don't care about that here. NG_CLI_ANALYTICS: 'false', }); const testRegistry = getGlobalVariable('package-registry'); export default
{ "end_byte": 1002, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts_1003_8957
async function () { // Windows Cmd and Powershell do not support autocompletion. Run a different set of tests to // confirm autocompletion skips the prompt appropriately. if (process.platform === 'win32') { await windowsTests(); return; } // Sets up autocompletion after user accepts a prompt from any command. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, `# Other content...`); const { stdout } = await execWithEnv( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'y\n' /* stdin: accept prompt */, ); if (!AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('CLI execution did not prompt for autocompletion setup when it should have.'); } const bashrcContents = await fs.readFile(bashrc, 'utf-8'); if (!bashrcContents.includes('source <(ng completion script)')) { throw new Error( 'Autocompletion was *not* added to `~/.bashrc` after accepting the setup prompt.', ); } if (!stdout.includes('Appended `source <(ng completion script)`')) { throw new Error('CLI did not print that it successfully set up autocompletion.'); } }); // Does nothing if the user rejects the autocompletion prompt. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, `# Other content...`); const { stdout } = await execWithEnv( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'n\n' /* stdin: reject prompt */, ); if (!AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('CLI execution did not prompt for autocompletion setup when it should have.'); } const bashrcContents = await fs.readFile(bashrc, 'utf-8'); if (bashrcContents.includes('ng completion')) { throw new Error( 'Autocompletion was incorrectly added to `~/.bashrc` after refusing the setup prompt.', ); } if (stdout.includes('Appended `source <(ng completion script)`')) { throw new Error( "CLI printed that it successfully set up autocompletion when it actually didn't.", ); } if (!stdout.includes("Ok, you won't be prompted again.")) { throw new Error('CLI did not inform the user they will not be prompted again.'); } }); // Does *not* prompt if the user already accepted (even if they delete the completion config). await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, '# Other commands...'); const { stdout: stdout1 } = await execWithEnv( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'y\n' /* stdin: accept prompt */, ); if (!AUTOCOMPLETION_PROMPT.test(stdout1)) { throw new Error('First execution did not prompt for autocompletion setup.'); } const bashrcContents1 = await fs.readFile(bashrc, 'utf-8'); if (!bashrcContents1.includes('source <(ng completion script)')) { throw new Error( '`~/.bashrc` file was not updated after the user accepted the autocompletion' + ` prompt. Contents:\n${bashrcContents1}`, ); } // User modifies their configuration and removes `ng completion`. await fs.writeFile(bashrc, '# Some new commands...'); const { stdout: stdout2 } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }); if (AUTOCOMPLETION_PROMPT.test(stdout2)) { throw new Error( 'Subsequent execution after rejecting autocompletion setup prompted again' + ' when it should not have.', ); } const bashrcContents2 = await fs.readFile(bashrc, 'utf-8'); if (bashrcContents2 !== '# Some new commands...') { throw new Error( '`~/.bashrc` file was incorrectly modified when using a modified `~/.bashrc`' + ` after previously accepting the autocompletion prompt. Contents:\n${bashrcContents2}`, ); } }); // Does *not* prompt if the user already rejected. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, '# Other commands...'); const { stdout: stdout1 } = await execWithEnv( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'n\n' /* stdin: reject prompt */, ); if (!AUTOCOMPLETION_PROMPT.test(stdout1)) { throw new Error('First execution did not prompt for autocompletion setup.'); } const { stdout: stdout2 } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }); if (AUTOCOMPLETION_PROMPT.test(stdout2)) { throw new Error( 'Subsequent execution after rejecting autocompletion setup prompted again' + ' when it should not have.', ); } const bashrcContents = await fs.readFile(bashrc, 'utf-8'); if (bashrcContents !== '# Other commands...') { throw new Error( '`~/.bashrc` file was incorrectly modified when the user never accepted the' + ` autocompletion prompt. Contents:\n${bashrcContents}`, ); } }); // Prompts user again on subsequent execution after accepting prompt but failing to setup. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, '# Other commands...'); // Make `~/.bashrc` readonly. This is enough for the CLI to verify that the file exists and // `ng completion` is not in it, but will fail when actually trying to modify the file. await fs.chmod(bashrc, 0o444); const err = await execAndCaptureError( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'y\n' /* stdin: accept prompt */, ); if (!err.message.includes('Failed to append autocompletion setup')) { throw new Error( `Failed first execution did not print the expected error message. Actual:\n${err.message}`, ); } // User corrects file permissions between executions. await fs.chmod(bashrc, 0o777); const { stdout: stdout2 } = await execWithEnv( 'ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }, 'y\n' /* stdin: accept prompt */, ); if (!AUTOCOMPLETION_PROMPT.test(stdout2)) { throw new Error( 'Subsequent execution after failed autocompletion setup did not prompt again when it should' + ' have.', ); } const bashrcContents = await fs.readFile(bashrc, 'utf-8'); if (!bashrcContents.includes('ng completion script')) { throw new Error( '`~/.bashrc` file does not include `ng completion` after the user never accepted the' + ` autocompletion prompt a second time. Contents:\n${bashrcContents}`, ); } }); // Does *not* prompt for `ng update` commands. await mockHome(async (home) => { // Use `ng update --help` so it's actually a no-op and we don't need to setup a project. const { stdout } = await execWithEnv('ng', ['update', '--help'], { ...DEFAULT_ENV, HOME: home, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('`ng update` command incorrectly prompted for autocompletion setup.'); } }); // Does *not* prompt for `ng completion` commands. await mockHome(async (home) => { const { stdout } = await execWithEnv('ng', ['completion'], { ...DEFAULT_ENV, HOME: home, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('`ng completion` command incorrectly prompted for autocompletion setup.'); } });
{ "end_byte": 8957, "start_byte": 1003, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts_8961_13954
// Does *not* prompt user for CI executions. { const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, CI: 'true', NG_FORCE_TTY: undefined, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('CI execution prompted for autocompletion setup but should not have.'); } } // Does *not* prompt user for non-TTY executions. { const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, NG_FORCE_TTY: 'false', }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error('Non-TTY execution prompted for autocompletion setup but should not have.'); } } // Does *not* prompt user for executions without a `$HOME`. { const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, HOME: undefined, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( 'Execution without a `$HOME` value prompted for autocompletion setup but' + ' should not have.', ); } } // Does *not* prompt user for executions without a `$SHELL`. { const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, SHELL: undefined, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( 'Execution without a `$SHELL` value prompted for autocompletion setup but' + ' should not have.', ); } } // Does *not* prompt user for executions from unknown shells. { const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, SHELL: '/usr/bin/unknown', }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( 'Execution with an unknown `$SHELL` value prompted for autocompletion setup' + ' but should not have.', ); } } // Does *not* prompt user when an RC file already uses `ng completion`. await mockHome(async (home) => { await fs.writeFile( path.join(home, '.bashrc'), ` # Some stuff... source <(ng completion script) # Some other stuff... `.trim(), ); const { stdout } = await execWithEnv('ng', ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( "Execution with an existing `ng completion` line in the user's RC file" + ' prompted for autocompletion setup but should not have.', ); } }); // Prompts when a global CLI install is present on the system. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, `# Other content...`); await execAndWaitForOutputToMatch('ng', ['config'], AUTOCOMPLETION_PROMPT, { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, }); }); // Does *not* prompt when a global CLI install is missing from the system. await mockHome(async (home) => { try { // Temporarily uninstall the global CLI binary from the system. await silentNpm(['uninstall', '--global', '@angular/cli', `--registry=${testRegistry}`]); // Setup a fake project directory with a local install of the CLI. const projectDir = path.join(home, 'project'); await fs.mkdir(projectDir); await silentNpm(['init', '-y', `--registry=${testRegistry}`], { cwd: projectDir }); await silentNpm(['install', '@angular/cli', `--registry=${testRegistry}`], { cwd: projectDir, }); const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, `# Other content...`); const localCliDir = path.join(projectDir, 'node_modules', '.bin'); const localCliBinary = path.join(localCliDir, 'ng'); const pathDirs = process.env['PATH']!.split(':'); const pathEnvVar = [...pathDirs, localCliDir].join(':'); const { stdout } = await execWithEnv(localCliBinary, ['config'], { ...DEFAULT_ENV, SHELL: '/bin/bash', HOME: home, PATH: pathEnvVar, }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( 'Execution without a global CLI install prompted for autocompletion setup but should' + ' not have.', ); } } finally { // Reinstall global CLI for remainder of the tests. await silentNpm(['install', '--global', '@angular/cli', `--registry=${testRegistry}`]); } }); } async function windowsTests(): Promise<void> { // Should *not* prompt on Windows, autocompletion isn't supported. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, `# Other content...`); const { stdout } = await execWithEnv('ng', ['config'], { ...env }); if (AUTOCOMPLETION_PROMPT.test(stdout)) { throw new Error( 'Execution prompted to set up autocompletion on Windows despite not actually being' + ' supported.', ); } }); }
{ "end_byte": 13954, "start_byte": 8961, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion.ts_0_7563
import { promises as fs } from 'fs'; import * as path from 'path'; import { getGlobalVariable } from '../../../utils/env'; import { mockHome } from '../../../utils/utils'; import { execAndCaptureError, execAndWaitForOutputToMatch, execWithEnv, silentNpm, } from '../../../utils/process'; const testRegistry = getGlobalVariable('package-registry'); export default async function () { // Windows Cmd and Powershell do not support autocompletion. Run a different set of tests to // confirm autocompletion fails gracefully. if (process.platform === 'win32') { await windowsTests(); return; } // Generates new `.bashrc` file. await mockHome(async (home) => { await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/bin/bash', }, ); const rcContents = await fs.readFile(path.join(home, '.bashrc'), 'utf-8'); const expected = ` # Load Angular CLI autocompletion. source <(ng completion script) `.trim(); if (!rcContents.includes(expected)) { throw new Error(`~/.bashrc does not contain autocompletion script. Contents:\n${rcContents}`); } }); // Generates new `.zshrc` file. await mockHome(async (home) => { await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/usr/bin/zsh', }, ); const rcContents = await fs.readFile(path.join(home, '.zshrc'), 'utf-8'); const expected = ` # Load Angular CLI autocompletion. source <(ng completion script) `.trim(); if (!rcContents.includes(expected)) { throw new Error(`~/.zshrc does not contain autocompletion script. Contents:\n${rcContents}`); } }); // Appends to existing `.bashrc` file. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/bin/bash', }, ); const rcContents = await fs.readFile(bashrc, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.bashrc does not match expectation. Contents:\n${rcContents}`); } }); // Appends to existing `.bash_profile` file. await mockHome(async (home) => { const bashProfile = path.join(home, '.bash_profile'); await fs.writeFile(bashProfile, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/bin/bash', }, ); const rcContents = await fs.readFile(bashProfile, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.bash_profile does not match expectation. Contents:\n${rcContents}`); } }); // Appends to existing `.profile` file (using Bash). await mockHome(async (home) => { const profile = path.join(home, '.profile'); await fs.writeFile(profile, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/bin/bash', }, ); const rcContents = await fs.readFile(profile, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.profile does not match expectation. Contents:\n${rcContents}`); } }); // Bash shell prefers `.bashrc`. await mockHome(async (home) => { const bashrc = path.join(home, '.bashrc'); await fs.writeFile(bashrc, '# `.bashrc` commands...'); const bashProfile = path.join(home, '.bash_profile'); await fs.writeFile(bashProfile, '# `.bash_profile` commands...'); const profile = path.join(home, '.profile'); await fs.writeFile(profile, '# `.profile` commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/bin/bash', }, ); const bashrcContents = await fs.readFile(bashrc, 'utf-8'); const bashrcExpected = `# \`.bashrc\` commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (bashrcContents !== bashrcExpected) { throw new Error(`~/.bashrc does not match expectation. Contents:\n${bashrcContents}`); } const bashProfileContents = await fs.readFile(bashProfile, 'utf-8'); if (bashProfileContents !== '# `.bash_profile` commands...') { throw new Error( `~/.bash_profile does not match expectation. Contents:\n${bashProfileContents}`, ); } const profileContents = await fs.readFile(profile, 'utf-8'); if (profileContents !== '# `.profile` commands...') { throw new Error(`~/.profile does not match expectation. Contents:\n${profileContents}`); } }); // Appends to existing `.zshrc` file. await mockHome(async (home) => { const zshrc = path.join(home, '.zshrc'); await fs.writeFile(zshrc, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/usr/bin/zsh', }, ); const rcContents = await fs.readFile(zshrc, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.zshrc does not match expectation. Contents:\n${rcContents}`); } }); // Appends to existing `.zsh_profile` file. await mockHome(async (home) => { const zshProfile = path.join(home, '.zsh_profile'); await fs.writeFile(zshProfile, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/usr/bin/zsh', }, ); const rcContents = await fs.readFile(zshProfile, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.zsh_profile does not match expectation. Contents:\n${rcContents}`); } }); // Appends to existing `.profile` file (using Zsh). await mockHome(async (home) => { const profile = path.join(home, '.profile'); await fs.writeFile(profile, '# Other commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/usr/bin/zsh', }, ); const rcContents = await fs.readFile(profile, 'utf-8'); const expected = `# Other commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (rcContents !== expected) { throw new Error(`~/.profile does not match expectation. Contents:\n${rcContents}`); } }); // Zsh prefers `.zshrc`.
{ "end_byte": 7563, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/completion/completion.ts_7566_12162
await mockHome(async (home) => { const zshrc = path.join(home, '.zshrc'); await fs.writeFile(zshrc, '# `.zshrc` commands...'); const zshProfile = path.join(home, '.zsh_profile'); await fs.writeFile(zshProfile, '# `.zsh_profile` commands...'); const profile = path.join(home, '.profile'); await fs.writeFile(profile, '# `.profile` commands...'); await execAndWaitForOutputToMatch( 'ng', ['completion'], /Appended `source <\(ng completion script\)`/, { ...process.env, 'SHELL': '/usr/bin/zsh', }, ); const zshrcContents = await fs.readFile(zshrc, 'utf-8'); const zshrcExpected = `# \`.zshrc\` commands... # Load Angular CLI autocompletion. source <(ng completion script) `; if (zshrcContents !== zshrcExpected) { throw new Error(`~/.zshrc does not match expectation. Contents:\n${zshrcContents}`); } const zshProfileContents = await fs.readFile(zshProfile, 'utf-8'); if (zshProfileContents !== '# `.zsh_profile` commands...') { throw new Error( `~/.zsh_profile does not match expectation. Contents:\n${zshProfileContents}`, ); } const profileContents = await fs.readFile(profile, 'utf-8'); if (profileContents !== '# `.profile` commands...') { throw new Error(`~/.profile does not match expectation. Contents:\n${profileContents}`); } }); // Fails for no `$HOME` directory. { const err = await execAndCaptureError('ng', ['completion'], { ...process.env, SHELL: '/bin/bash', HOME: undefined, }); if (!err.message.includes('`$HOME` environment variable not set.')) { throw new Error(`Expected unset \`$HOME\` error message, but got:\n\n${err.message}`); } } // Fails for no `$SHELL`. await mockHome(async (home) => { const err = await execAndCaptureError('ng', ['completion'], { ...process.env, SHELL: undefined, }); if (!err.message.includes('`$SHELL` environment variable not set.')) { throw new Error(`Expected unset \`$SHELL\` error message, but got:\n\n${err.message}`); } }); // Fails for unknown `$SHELL`. await mockHome(async (home) => { const err = await execAndCaptureError('ng', ['completion'], { ...process.env, SHELL: '/usr/bin/unknown', }); if (!err.message.includes('Unknown `$SHELL` environment variable')) { throw new Error(`Expected unknown \`$SHELL\` error message, but got:\n\n${err.message}`); } }); // Does *not* warn when a global CLI install is present on the system. await mockHome(async (home) => { const { stdout } = await execWithEnv('ng', ['completion'], { ...process.env, 'SHELL': '/usr/bin/zsh', }); if (stdout.includes('there does not seem to be a global install of the Angular CLI')) { throw new Error(`CLI warned about missing global install, but one should exist.`); } }); // Warns when a global CLI install is *not* present on the system. await mockHome(async (home) => { try { // Temporarily uninstall the global CLI binary from the system. await silentNpm(['uninstall', '--global', '@angular/cli', `--registry=${testRegistry}`]); // Setup a fake project directory with a local install of the CLI. const projectDir = path.join(home, 'project'); await fs.mkdir(projectDir); await silentNpm(['init', '-y', `--registry=${testRegistry}`], { cwd: projectDir }); await silentNpm(['install', '@angular/cli', `--registry=${testRegistry}`], { cwd: projectDir, }); // Invoke the local CLI binary. const localCliBinary = path.join(projectDir, 'node_modules', '.bin', 'ng'); const { stdout } = await execWithEnv(localCliBinary, ['completion'], { ...process.env, 'SHELL': '/usr/bin/zsh', }); if (stdout.includes('there does not seem to be a global install of the Angular CLI')) { throw new Error(`CLI warned about missing global install, but one should exist.`); } } finally { // Reinstall global CLI for remainder of the tests. await silentNpm(['install', '--global', '@angular/cli', `--registry=${testRegistry}`]); } }); } async function windowsTests(): Promise<void> { // Should fail with a clear error message. const err = await execAndCaptureError('ng', ['completion']); if (!err.message.includes("Cmd and Powershell don't support command autocompletion")) { throw new Error( `Expected Windows autocompletion to fail with custom error, but got:\n\n${err.message}`, ); } }
{ "end_byte": 12162, "start_byte": 7566, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/completion/completion.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/secure-registry.ts_0_1567
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs'; import { getActivePackageManager, installWorkspacePackages } from '../../../utils/packages'; import { git, ng } from '../../../utils/process'; import { createNpmConfigForAuthentication } from '../../../utils/registry'; import { expectToFail } from '../../../utils/utils'; export default async function () { // The environment variable has priority over the .npmrc delete process.env['NPM_CONFIG_REGISTRY']; const isNpm = getActivePackageManager() === 'npm'; const command = ['add', '@angular/pwa', '--skip-confirmation']; await expectFileNotToExist('public/manifest.webmanifest'); // Works with unscoped registry authentication details if (!isNpm) { // NPM no longer support unscoped. await createNpmConfigForAuthentication(false); await ng(...command); await expectFileToExist('public/manifest.webmanifest'); await git('clean', '-dxf'); } // Works with scoped registry authentication details await expectFileNotToExist('public/manifest.webmanifest'); await createNpmConfigForAuthentication(true); await ng(...command); await expectFileToExist('public/manifest.webmanifest'); // Invalid authentication token if (isNpm) { // NPM no longer support unscoped. await createNpmConfigForAuthentication(false, true); await expectToFail(() => ng(...command)); } await createNpmConfigForAuthentication(true, true); await expectToFail(() => ng(...command)); await git('clean', '-dxf'); await installWorkspacePackages(); }
{ "end_byte": 1567, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/secure-registry.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/base.ts_0_681
import { assetDir } from '../../../utils/assets'; import { deleteFile, expectFileToExist, symlinkFile } from '../../../utils/fs'; import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { await symlinkFile(assetDir('add-collection'), `./node_modules/add-collection`, 'dir'); await ng('add', 'add-collection'); await expectFileToExist('empty-file'); await ng('add', 'add-collection', '--name=blah'); await expectFileToExist('blah'); await expectToFail(() => ng('add', 'add-collection')); // File already exists. // Cleanup the package await deleteFile('node_modules/add-collection'); }
{ "end_byte": 681, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/base.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/add-version.ts_0_436
import { expectFileToExist, expectFileToMatch, rimraf } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('add', '@angular-devkit-tests/ng-add-simple@^1.0.0', '--skip-confirmation'); await expectFileToMatch('package.json', /\/ng-add-simple.*\^1\.0\.0/); await expectFileToExist('ng-add-test'); await rimraf('node_modules/@angular-devkit-tests/ng-add-simple'); }
{ "end_byte": 436, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/add-version.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/yarn-env-vars.ts_0_1074
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs'; import { getActivePackageManager } from '../../../utils/packages'; import { git, ng } from '../../../utils/process'; import { createNpmConfigForAuthentication, setNpmEnvVarsForAuthentication, } from '../../../utils/registry'; export default async function () { // Yarn specific test that tests YARN_ env variables. // https://classic.yarnpkg.com/en/docs/envvars/ if (getActivePackageManager() !== 'yarn') { return; } const command = ['add', '@angular/pwa', '--skip-confirmation']; // Environment variables only await expectFileNotToExist('public/manifest.webmanifest'); setNpmEnvVarsForAuthentication(false, true); await ng(...command); await expectFileToExist('public/manifest.webmanifest'); await git('clean', '-dxf'); // Mix of config file and env vars works await expectFileNotToExist('public/manifest.webmanifest'); await createNpmConfigForAuthentication(false, true); await ng(...command); await expectFileToExist('public/manifest.webmanifest'); }
{ "end_byte": 1074, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/yarn-env-vars.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/add-material.ts_0_1313
import { assertIsError } from '../../../utils/utils'; import { expectFileToMatch, rimraf } from '../../../utils/fs'; import { getActivePackageManager, uninstallPackage } from '../../../utils/packages'; import { ng } from '../../../utils/process'; import { isPrereleaseCli } from '../../../utils/project'; import { appendFile } from 'node:fs/promises'; export default async function () { // forcibly remove in case another test doesn't clean itself up await rimraf('node_modules/@angular/material'); const isPrerelease = await isPrereleaseCli(); const tag = isPrerelease ? '@next' : ''; if (getActivePackageManager() === 'npm') { await appendFile('.npmrc', '\nlegacy-peer-deps=true'); } try { await ng('add', `@angular/material${tag}`, '--unknown', '--skip-confirmation'); } catch (error) { assertIsError(error); if (!(error as Error).message.includes(`Unknown option: '--unknown'`)) { throw error; } } await ng( 'add', `@angular/material${tag}`, '--theme', 'custom', '--verbose', '--skip-confirmation', ); await expectFileToMatch('package.json', /@angular\/material/); // Clean up existing cdk package // Not doing so can cause adding material to fail if an incompatible cdk is present await uninstallPackage('@angular/cdk'); }
{ "end_byte": 1313, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/add-material.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/file.ts_0_312
import { assetDir } from '../../../utils/assets'; import { expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('add', assetDir('add-collection.tgz'), '--name=blah', '--skip-confirmation'); await expectFileToExist('blah'); }
{ "end_byte": 312, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/file.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts_0_629
import { getGlobalVariable } from '../../../utils/env'; import { expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { const testRegistry = getGlobalVariable('package-registry'); // Set an invalid registry process.env['NPM_CONFIG_REGISTRY'] = 'http://127.0.0.1:9999'; await expectToFail(() => ng('add', '@angular/pwa', '--skip-confirmation')); await ng('add', `--registry=${testRegistry}`, '@angular/pwa', '--skip-confirmation'); await expectFileToExist('public/manifest.webmanifest'); }
{ "end_byte": 629, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/peer.ts_0_816
import { assetDir } from '../../../utils/assets'; import { ng } from '../../../utils/process'; const warning = 'Adding the package may not succeed.'; export default async function () { const { stdout: bad } = await ng( 'add', assetDir('add-collection-peer-bad'), '--skip-confirmation', ); if (!bad.includes(warning)) { throw new Error('peer warning not shown on bad package'); } const { stdout: base } = await ng('add', assetDir('add-collection'), '--skip-confirmation'); if (base.includes(warning)) { throw new Error('peer warning shown on base package'); } const { stdout: good } = await ng( 'add', assetDir('add-collection-peer-good'), '--skip-confirmation', ); if (good.includes(warning)) { throw new Error('peer warning shown on good package'); } }
{ "end_byte": 816, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/peer.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts_0_2052
import { appendFile } from 'fs/promises'; import { expectFileToMatch, rimraf } from '../../../utils/fs'; import { getActivePackageManager, uninstallPackage } from '../../../utils/packages'; import { ng } from '../../../utils/process'; import { isPrereleaseCli } from '../../../utils/project'; export default async function () { // forcibly remove in case another test doesn't clean itself up. await rimraf('node_modules/@angular/localize'); // If using npm, enable the force option to allow testing the output behavior of the // `ng add` command itself and not the behavior of npm which may otherwise fail depending // on the npm version in use and the version specifier supplied in each test. if (getActivePackageManager() === 'npm') { await appendFile('.npmrc', '\nforce=true\n'); } const tag = (await isPrereleaseCli()) ? '@next' : ''; await ng('add', `@angular/localize${tag}`, '--skip-confirmation'); await expectFileToMatch('package.json', /@angular\/localize/); const output1 = await ng('add', '@angular/localize', '--skip-confirmation'); if (!output1.stdout.includes('Skipping installation: Package already installed')) { throw new Error('Installation was not skipped'); } const output2 = await ng('add', '@angular/localize@latest', '--skip-confirmation'); if (output2.stdout.includes('Skipping installation: Package already installed')) { throw new Error('Installation should not have been skipped'); } // v12.2.0 has a package.json engine field that supports Node.js v16+ const output3 = await ng('add', '@angular/[email protected]', '--skip-confirmation'); if (output3.stdout.includes('Skipping installation: Package already installed')) { throw new Error('Installation should not have been skipped'); } const output4 = await ng('add', '@angular/localize@12', '--skip-confirmation'); if (!output4.stdout.includes('Skipping installation: Package already installed')) { throw new Error('Installation was not skipped'); } await uninstallPackage('@angular/localize'); }
{ "end_byte": 2052, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/npm-config.ts_0_285
import { writeFile } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { // Works with before option await writeFile('.npmrc', `before=${new Date().toISOString()}`); await ng('add', '@angular/pwa', '--skip-confirmation'); }
{ "end_byte": 285, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/npm-config.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts_0_2542
import { getGlobalVariable } from '../../../utils/env'; import { expectFileToExist, readFile, rimraf } from '../../../utils/fs'; import { installWorkspacePackages } from '../../../utils/packages'; import { ng } from '../../../utils/process'; import { updateJsonFile } from '../../../utils/project'; const snapshots = require('../../../ng-snapshot/package.json'); export default async function () { // forcibly remove in case another test doesn't clean itself up await rimraf('node_modules/@angular/pwa'); await ng('add', '@angular/pwa', '--skip-confirmation'); await expectFileToExist('public/manifest.webmanifest'); // Angular PWA doesn't install as a dependency const { dependencies, devDependencies } = JSON.parse(await readFile('package.json')); const hasPWADep = Object.keys({ ...dependencies, ...devDependencies }).some( (d) => d === '@angular/pwa', ); if (hasPWADep) { throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`); } const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots']; if (isSnapshotBuild) { let needInstall = false; await updateJsonFile('package.json', (packageJson) => { const dependencies = packageJson['dependencies']; // Iterate over all of the packages to update them to the snapshot version. for (const [name, version] of Object.entries(snapshots.dependencies)) { if (name in dependencies && dependencies[name] !== version) { dependencies[name] = version; needInstall = true; } } }); if (needInstall) { await installWorkspacePackages(); } } // It should generate a SW configuration file (`ngsw.json`). const ngswPath = 'dist/test-project/browser/ngsw.json'; await ng('build'); await expectFileToExist(ngswPath); // It should correctly generate assetGroups and include at least one URL in each group. const ngswJson = JSON.parse(await readFile(ngswPath)); // @ts-ignore const assetGroups: any[] = ngswJson.assetGroups.map(({ name, urls }) => ({ name, urlCount: urls.length, })); const emptyAssetGroups = assetGroups.filter(({ urlCount }) => urlCount === 0); if (assetGroups.length === 0) { throw new Error("Expected 'ngsw.json' to contain at least one asset-group."); } if (emptyAssetGroups.length > 0) { throw new Error( 'Expected all asset-groups to contain at least one URL, but the following groups are empty: ' + emptyAssetGroups.map(({ name }) => name).join(', '), ); } }
{ "end_byte": 2542, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/dir.ts_0_308
import { assetDir } from '../../../utils/assets'; import { expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('add', assetDir('add-collection'), '--name=blah', '--skip-confirmation'); await expectFileToExist('blah'); }
{ "end_byte": 308, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/dir.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/add/add.ts_0_439
import { expectFileToExist, expectFileToMatch, rimraf } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('add', '@angular-devkit-tests/ng-add-simple', '--skip-confirmation'); await expectFileToMatch('package.json', /@angular-devkit-tests\/ng-add-simple/); await expectFileToExist('ng-add-test'); await rimraf('node_modules/@angular-devkit-tests/ng-add-simple'); }
{ "end_byte": 439, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/add/add.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/ssr-http-requests-assets.ts_0_2641
import assert from 'node:assert'; import { killAllProcesses, ng } from '../../../utils/process'; import { rimraf, writeMultipleFiles } from '../../../utils/fs'; import { installWorkspacePackages } from '../../../utils/packages'; import { ngServe, useSha } from '../../../utils/project'; export default async function () { // Forcibly remove in case another test doesn't clean itself up. await rimraf('node_modules/@angular/ssr'); await ng('add', '@angular/ssr', '--server-routing', '--skip-confirmation'); await useSha(); await installWorkspacePackages(); await writeMultipleFiles({ // Add http client and route 'src/app/app.config.ts': ` import { ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { provideClientHydration } from '@angular/platform-browser'; import { provideHttpClient, withFetch } from '@angular/common/http'; export const appConfig: ApplicationConfig = { providers: [ provideRouter([{ path: '', component: HomeComponent, }]), provideClientHydration(), provideHttpClient(withFetch()), ], }; `, // Add asset 'public/media.json': JSON.stringify({ dataFromAssets: true }), // Update component to do an HTTP call to asset. 'src/app/app.component.ts': ` import { Component, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterOutlet } from '@angular/router'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, RouterOutlet], template: \` <p>{{ data | json }}</p> <router-outlet></router-outlet> \`, }) export class AppComponent { data: any; constructor() { const http = inject(HttpClient); http.get('/media.json').toPromise().then((d) => { this.data = d; }); } } `, }); await ng('generate', 'component', 'home'); const match = /<p>{[\S\s]*"dataFromAssets":[\s\S]*true[\S\s]*}<\/p>/; const port = await ngServe('--no-ssl'); assert.match(await (await fetch(`http://localhost:${port}/`)).text(), match); await killAllProcesses(); try { process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; const sslPort = await ngServe('--ssl'); assert.match(await (await fetch(`https://localhost:${sslPort}/`)).text(), match); } finally { process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'; } }
{ "end_byte": 2641, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/ssr-http-requests-assets.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/serve-path.ts_0_790
import * as assert from 'assert'; import { ngServe } from '../../../utils/project'; export default async function () { // TODO(architect): Delete this test. It is now in devkit/build-angular. const port = await ngServe('--serve-path', 'test/'); return Promise.resolve() .then(() => fetch(`http://localhost:${port}/test`, { headers: { 'Accept': 'text/html' } })) .then(async (response) => { assert.strictEqual(response.status, 200); assert.match(await response.text(), /<app-root><\/app-root>/); }) .then(() => fetch(`http://localhost:${port}/test/abc`, { headers: { 'Accept': 'text/html' } })) .then(async (response) => { assert.strictEqual(response.status, 200); assert.match(await response.text(), /<app-root><\/app-root>/); }); }
{ "end_byte": 790, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/serve-path.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/assets.ts_0_2281
import assert from 'node:assert'; import { randomUUID } from 'node:crypto'; import { mkdir, rm, writeFile } from 'node:fs/promises'; import { ngServe, updateJsonFile } from '../../../utils/project'; import { getGlobalVariable } from '../../../utils/env'; export default async function () { const outsideDirectoryName = `../outside-${randomUUID()}`; await updateJsonFile('angular.json', (json) => { // Ensure assets located outside the workspace root work with the dev server json.projects['test-project'].architect.build.options.assets.push({ 'input': outsideDirectoryName, 'glob': '**/*', 'output': './outside', }); }); await mkdir(outsideDirectoryName); try { await writeFile(`${outsideDirectoryName}/some-asset.xyz`, 'XYZ'); const port = await ngServe(); let response = await fetch(`http://localhost:${port}/favicon.ico`); assert.strictEqual(response.status, 200, 'favicon.ico response should be ok'); response = await fetch(`http://localhost:${port}/outside/some-asset.xyz`); assert.strictEqual(response.status, 200, 'outside/some-asset.xyz response should be ok'); assert.strictEqual(await response.text(), 'XYZ', 'outside/some-asset.xyz content is wrong'); // A non-existent HTML file request with accept header should fallback to the index HTML response = await fetch(`http://localhost:${port}/does-not-exist.html`, { headers: { accept: 'text/html' }, }); assert.strictEqual( response.status, 200, 'non-existent file response should fallback and be ok', ); assert.match( await response.text(), /<app-root/, 'non-existent file response should fallback and contain html', ); // Vite will incorrectly fallback in all non-existent cases so skip last test case // TODO: Remove conditional when Vite handles this case if (getGlobalVariable('argv')['esbuild']) { return; } // A non-existent file without an html accept header should not be found. response = await fetch(`http://localhost:${port}/does-not-exist.png`); assert.strictEqual(response.status, 404, 'non-existent file response should be not found'); } finally { await rm(outsideDirectoryName, { force: true, recursive: true }); } }
{ "end_byte": 2281, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/assets.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/head-request.ts_0_828
import { ngServe } from '../../../utils/project'; export default async function () { const port = await ngServe(); // HTML await checkHeadForUrl(`http://localhost:${port}/index.html`); // Generated JS await checkHeadForUrl(`http://localhost:${port}/main.js`); // Generated CSS await checkHeadForUrl(`http://localhost:${port}/styles.css`); // Configured asset await checkHeadForUrl(`http://localhost:${port}/favicon.ico`); } async function checkHeadForUrl(url: string): Promise<void> { const result = await fetch(url, { method: 'HEAD' }); const content = await result.blob(); if (content.size !== 0) { throw new Error(`Expected "size" to be "0" but got "${content.size}".`); } if (result.status !== 200) { throw new Error(`Expected "status" to be "200" but got "${result.status}".`); } }
{ "end_byte": 828, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/head-request.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/reload-shims.ts_0_722
import { prependToFile, writeFile } from '../../../utils/fs'; import { execAndWaitForOutputToMatch } from '../../../utils/process'; export default async function () { // Simulate a JS library using a Node.js specific module await writeFile('src/node-usage.js', `const path = require('path');\n`); await prependToFile('src/main.ts', `import './node-usage';\n`); // Make sure serve is consistent with build await execAndWaitForOutputToMatch( 'ng', ['build'], /Module not found: Error: Can't resolve 'path'/, ); // The Node.js specific module should not be found await execAndWaitForOutputToMatch( 'ng', ['serve', '--port=0'], /Module not found: Error: Can't resolve 'path'/, ); }
{ "end_byte": 722, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/reload-shims.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/serve/preflight-request.ts_0_476
import { ngServe } from '../../../utils/project'; export default async function () { const port = await ngServe(); const result = await fetch(`http://localhost:${port}/main.js`, { method: 'OPTIONS' }); const content = await result.blob(); if (content.size !== 0) { throw new Error(`Expected "size" to be "0" but got "${content.size}".`); } if (result.status !== 204) { throw new Error(`Expected "status" to be "204" but got "${result.status}".`); } }
{ "end_byte": 476, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/serve/preflight-request.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/e2e/e2e-and-serve.ts_0_228
import { silentNg } from '../../../utils/process'; import { ngServe } from '../../../utils/project'; export default async function () { // Should run side-by-side with `ng serve` await ngServe(); await silentNg('e2e'); }
{ "end_byte": 228, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/e2e/e2e-and-serve.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/e2e/protractor-config.ts_0_353
import { moveFile } from '../../../utils/fs'; import { silentNg } from '../../../utils/process'; export default async function () { // Should accept different config file await moveFile('./e2e/protractor.conf.js', './e2e/renamed-protractor.conf.js'); await silentNg('e2e', 'test-project', '--protractor-config=e2e/renamed-protractor.conf.js'); }
{ "end_byte": 353, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/e2e/protractor-config.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/e2e/suite.ts_0_478
import { silentNg } from '../../../utils/process'; import { replaceInFile } from '../../../utils/fs'; export default async function () { // Suites block need to be added in the protractor.conf.js file to test suites await replaceInFile( 'e2e/protractor.conf.js', `allScriptsTimeout: 11000,`, `allScriptsTimeout: 11000, suites: { app: './e2e/src/app.e2e-spec.ts' }, `, ); await silentNg('e2e', 'test-project', '--suite=app'); }
{ "end_byte": 478, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/e2e/suite.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/e2e/multiple-specs.ts_0_529
import { silentNg } from '../../../utils/process'; import { moveFile, copyFile } from '../../../utils/fs'; export default async function () { // Should accept different multiple spec files await moveFile('./e2e/src/app.e2e-spec.ts', './e2e/src/renamed-app.e2e-spec.ts'); await copyFile('./e2e/src/renamed-app.e2e-spec.ts', './e2e/src/another-app.e2e-spec.ts'); await silentNg( 'e2e', 'test-project', '--specs', './e2e/renamed-app.e2e-spec.ts', '--specs', './e2e/another-app.e2e-spec.ts', ); }
{ "end_byte": 529, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/e2e/multiple-specs.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/help/help-hidden.ts_0_546
import { silentNg } from '../../../utils/process'; export default async function () { const { stdout: stdoutNew } = await silentNg('--help'); if (/(easter-egg)|(ng make-this-awesome)|(ng init)/.test(stdoutNew)) { throw new Error( 'Expected to not match "(easter-egg)|(ng make-this-awesome)|(ng init)" in help output.', ); } const { stdout: ngGenerate } = await silentNg('--help', 'generate', 'component'); if (ngGenerate.includes('--path')) { throw new Error('Expected to not match "--path" in help output.'); } }
{ "end_byte": 546, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/help/help-hidden.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/help/help-json.ts_0_2933
import { silentNg } from '../../../utils/process'; export default async function () { // This test is use as a sanity check. const addHelpOutputSnapshot = JSON.stringify({ 'name': 'config', 'command': 'ng config [json-path] [value]', 'shortDescription': 'Retrieves or sets Angular configuration values in the angular.json file for the workspace.', 'longDescriptionRelativePath': '@angular/cli/src/commands/config/long-description.md', 'longDescription': 'A workspace has a single CLI configuration file, `angular.json`, at the top level.\nThe `projects` object contains a configuration object for each project in the workspace.\n\nYou can edit the configuration directly in a code editor,\nor indirectly on the command line using this command.\n\nThe configurable property names match command option names,\nexcept that in the configuration file, all names must use camelCase,\nwhile on the command line options can be given dash-case.\n\nFor further details, see [Workspace Configuration](reference/configs/workspace-config).\n\nFor configuration of CLI usage analytics, see [ng analytics](cli/analytics).\n', 'options': [ { 'name': 'global', 'type': 'boolean', 'aliases': ['g'], 'default': false, 'description': "Access the global configuration in the caller's home directory.", }, { 'name': 'help', 'type': 'boolean', 'description': 'Shows a help message for this command in the console.', }, { 'name': 'json-path', 'type': 'string', 'description': 'The configuration key to set or query, in JSON path format. For example: "a[3].foo.bar[2]". If no new value is provided, returns the current value of this key.', 'positional': 0, }, { 'name': 'value', 'type': 'string', 'description': 'If provided, a new value for the given configuration key.', 'positional': 1, }, ], }); const { stdout } = await silentNg('config', '--help', '--json-help'); const output = JSON.stringify(JSON.parse(stdout.trim())); if (output !== addHelpOutputSnapshot) { throw new Error( `ng config JSON help output didn\'t match snapshot.\n\nExpected "${output}" to be "${addHelpOutputSnapshot}".`, ); } const { stdout: stdout2 } = await silentNg('--help', '--json-help'); try { JSON.parse(stdout2.trim()); } catch (error) { throw new Error( `'ng --help ---json-help' failed to return JSON.\n${ error instanceof Error ? error.message : error }`, ); } const { stdout: stdout3 } = await silentNg('generate', '--help', '--json-help'); try { JSON.parse(stdout3.trim()); } catch (error) { throw new Error( `'ng generate --help ---json-help' failed to return JSON.\n${ error instanceof Error ? error.message : error }`, ); } }
{ "end_byte": 2933, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/help/help-json.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/analytics/analytics-info.ts_0_1023
import { execAndWaitForOutputToMatch } from '../../../utils/process'; import { updateJsonFile } from '../../../utils/project'; export default async function () { // Should be disabled by default. await configureTest(undefined /** analytics */); await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, { NG_FORCE_TTY: '0', // Disable prompts }); await configureTest('1dba0835-38a3-4957-bf34-9974e2df0df3' /** analytics */); await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: enabled/, { NG_FORCE_TTY: '0', // Disable prompts }); await configureTest(false /** analytics */); await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, { NG_FORCE_TTY: '0', // Disable prompts }); } async function configureTest(analytics: false | string | undefined): Promise<void> { await updateJsonFile('angular.json', (config) => { config.cli ??= {}; config.cli.analytics = analytics; }); }
{ "end_byte": 1023, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/analytics/analytics-info.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/analytics/analytics-enable-disable.ts_0_393
import assert from 'node:assert'; import { readFile } from '../../../utils/fs'; import { ng } from '../../../utils/process'; export default async function () { await ng('analytics', 'enable'); assert.ok(JSON.parse(await readFile('angular.json')).cli.analytics); await ng('analytics', 'disable'); assert.strictEqual(JSON.parse(await readFile('angular.json')).cli.analytics, false); }
{ "end_byte": 393, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/analytics/analytics-enable-disable.ts" }
angular-cli/tests/legacy-cli/e2e/tests/commands/analytics/ask-analytics-command.ts_0_1510
import { execWithEnv } from '../../../utils/process'; import { mockHome } from '../../../utils/utils'; const ANALYTICS_PROMPT = /Would you like to share pseudonymous usage data/; export default async function () { // CLI should prompt for analytics permissions. await mockHome(async () => { const { stdout } = await execWithEnv( 'ng', ['config'], { ...process.env, NG_FORCE_TTY: '1', NG_FORCE_AUTOCOMPLETE: 'false', }, 'n\n' /* stdin */, ); if (!ANALYTICS_PROMPT.test(stdout)) { throw new Error('CLI did not prompt for analytics permission.'); } }); // CLI should skip analytics prompt with `NG_CLI_ANALYTICS=false`. await mockHome(async () => { const { stdout } = await execWithEnv('ng', ['config'], { ...process.env, NG_FORCE_TTY: '1', NG_CLI_ANALYTICS: 'false', NG_FORCE_AUTOCOMPLETE: 'false', }); if (ANALYTICS_PROMPT.test(stdout)) { throw new Error('CLI prompted for analytics permission when it should be forced off.'); } }); // CLI should skip analytics prompt during `ng update`. await mockHome(async () => { const { stdout } = await execWithEnv('ng', ['update', '--help'], { ...process.env, NG_FORCE_TTY: '1', NG_FORCE_AUTOCOMPLETE: 'false', }); if (ANALYTICS_PROMPT.test(stdout)) { throw new Error( 'CLI prompted for analytics permission during an update where it should not' + ' have.', ); } }); }
{ "end_byte": 1510, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/commands/analytics/ask-analytics-command.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/ts-paths.ts_0_1794
import { appendToFile, createDir, replaceInFile, rimraf, writeMultipleFiles } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateTsConfig } from '../../utils/project'; export default async function () { await updateTsConfig((json) => { json['compilerOptions']['baseUrl'] = './src'; json['compilerOptions']['paths'] = { '@shared': ['app/shared'], '@shared/*': ['app/shared/*'], '@root/*': ['./*'], }; }); await createDir('src/app/shared'); await writeMultipleFiles({ 'src/meaning-too.ts': 'export var meaning = 42;', 'src/app/shared/meaning.ts': 'export var meaning = 42;', 'src/app/shared/index.ts': `export * from './meaning'`, }); await replaceInFile('src/main.ts', './app/app.component', '@root/app/app.component'); await ng('build', '--configuration=development'); await updateTsConfig((json) => { json['compilerOptions']['paths']['*'] = ['*', 'app/shared/*']; }); await appendToFile( 'src/app/app.component.ts', ` import { meaning } from 'app/shared/meaning'; import { meaning as meaning2 } from '@shared'; import { meaning as meaning3 } from '@shared/meaning'; import { meaning as meaning4 } from 'meaning'; import { meaning as meaning5 } from 'meaning-too'; // need to use imports otherwise they are ignored and // no error is outputted, even if baseUrl/paths don't work console.log(meaning) console.log(meaning2) console.log(meaning3) console.log(meaning4) console.log(meaning5) `, ); await ng('build', '--configuration=development'); // Simulate no package.json file which causes Webpack to have an undefined 'descriptionFileData'. await rimraf('package.json'); await ng('build', '--configuration=development'); }
{ "end_byte": 1794, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/ts-paths.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/output-dir.ts_0_1370
import { getGlobalVariable } from '../../utils/env'; import { expectFileToExist } from '../../utils/fs'; import { expectGitToBeClean } from '../../utils/git'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; import { expectToFail } from '../../utils/utils'; export default function () { // TODO(architect): Delete this test. It is now in devkit/build-angular. const usingWebpack = !getGlobalVariable('argv')['esbuild']; return ng('build', '--output-path', 'build-output', '--configuration=development') .then(() => expectFileToExist(`./build-output/${usingWebpack ? '' : 'browser/'}index.html`)) .then(() => expectFileToExist(`./build-output/${usingWebpack ? '' : 'browser/'}main.js`)) .then(() => expectToFail(expectGitToBeClean)) .then(() => updateJsonFile('angular.json', (workspaceJson) => { const appArchitect = workspaceJson.projects['test-project'].architect; appArchitect.build.options.outputPath = 'config-build-output'; }), ) .then(() => ng('build', '--configuration=development')) .then(() => expectFileToExist(`./config-build-output/${usingWebpack ? '' : 'browser/'}index.html`), ) .then(() => expectFileToExist(`./config-build-output/${usingWebpack ? '' : 'browser/'}main.js`)) .then(() => expectToFail(expectGitToBeClean)); }
{ "end_byte": 1370, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/output-dir.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/sourcemap.ts_0_1928
import * as fs from 'fs'; import { expectFileToExist } from '../../utils/fs'; import { ng } from '../../utils/process'; import { getGlobalVariable } from '../../utils/env'; export default async function () { const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; // The below is needed to cache bundles and verify that sourcemaps are generated // corretly when output-hashing is disabled. await ng('build', '--output-hashing=bundles', '--source-map', '--configuration=development'); await ng('build', '--output-hashing=none', '--source-map'); await testForSourceMaps(useWebpackBuilder ? 3 : 2); await ng('build', '--output-hashing=none', '--source-map', '--configuration=development'); await testForSourceMaps(useWebpackBuilder ? 4 : 2); } async function testForSourceMaps(expectedNumberOfFiles: number): Promise<void> { await expectFileToExist('dist/test-project/browser/main.js.map'); const files = fs.readdirSync('./dist/test-project/browser'); let count = 0; for (const file of files) { if (!file.endsWith('.js')) { continue; } ++count; if (!files.includes(file + '.map')) { throw new Error('Sourcemap not generated for ' + file); } const content = fs.readFileSync('./dist/test-project/browser/' + file, 'utf8'); let lastLineIndex = content.lastIndexOf('\n'); if (lastLineIndex === content.length - 1) { // Skip empty last line lastLineIndex = content.lastIndexOf('\n', lastLineIndex - 1); } const comment = lastLineIndex !== -1 && content.slice(lastLineIndex).trim(); if (comment !== `//# sourceMappingURL=${file}.map`) { console.log('CONTENT:\n' + content); throw new Error('Sourcemap comment not generated for ' + file); } } if (count < expectedNumberOfFiles) { throw new Error( `Javascript file count is low. Expected ${expectedNumberOfFiles} but found ${count}`, ); } }
{ "end_byte": 1928, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/sourcemap.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/ts-standard-decorators.ts_0_1155
import { getGlobalVariable } from '../../utils/env'; import { ng } from '../../utils/process'; import { updateJsonFile, updateTsConfig } from '../../utils/project'; export default async function () { // Update project to disable experimental decorators await updateTsConfig((json) => { json['compilerOptions']['experimentalDecorators'] = false; }); // Default production build await ng('build'); // Production build with JIT await updateJsonFile('angular.json', (json) => { // Remove bundle budgets to avoid a build error due to the expected increased output size // of a JIT production build. json.projects['test-project'].architect.build.configurations.production.budgets = []; }); if (!getGlobalVariable('argv')['esbuild']) { await ng('build', '--no-aot', '--no-build-optimizer'); } // Default development build await ng('build', '--configuration=development'); // Development build with JIT await ng('build', '--configuration=development', '--no-aot'); // Unit tests (JIT only) await ng('test', '--no-watch'); // E2E tests to ensure application functions in a browser await ng('e2e'); }
{ "end_byte": 1155, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/ts-standard-decorators.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts_0_1738
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { appendToFile, createDir, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { await ng('generate', 'library', 'mylib'); await createLibraryEntryPoint('secondary'); await createLibraryEntryPoint('another'); // Scenario #1 where we use wildcard path mappings for secondary entry-points. await updateJsonFile('tsconfig.json', (json) => { json.compilerOptions.paths = { 'mylib': ['./dist/mylib'], 'mylib/*': ['./dist/mylib/*'] }; }); await appendToFile( 'src/app/app.config.ts', ` import * as secondary from 'mylib/secondary'; import * as another from 'mylib/another'; console.log({ secondary, another }); `, ); await ng('build', 'mylib'); await ng('build'); // Scenario #2 where we don't use wildcard path mappings. await updateJsonFile('tsconfig.json', (json) => { json.compilerOptions.paths = { 'mylib': ['./dist/mylib'], 'mylib/secondary': ['./dist/mylib/secondary'], 'mylib/another': ['./dist/mylib/another'], }; }); await ng('build'); } async function createLibraryEntryPoint(name: string): Promise<void> { await createDir(`projects/mylib/${name}`); await writeFile(`projects/mylib/${name}/index.ts`, `export const foo = 'foo';`); await writeFile( `projects/mylib/${name}/ng-package.json`, JSON.stringify({ lib: { entryFile: 'index.ts', }, }), ); }
{ "end_byte": 1738, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/poll.ts_0_1185
import { setTimeout } from 'node:timers/promises'; import { getGlobalVariable } from '../../utils/env'; import { appendToFile } from '../../utils/fs'; import { waitForAnyProcessOutputToMatch } from '../../utils/process'; import { ngServe } from '../../utils/project'; import { expectToFail } from '../../utils/utils'; const webpackGoodRegEx = getGlobalVariable('argv')['esbuild'] ? /Application bundle generation complete\./ : / Compiled successfully\./; export default async function () { await ngServe('--poll=10000'); // Wait before editing a file. // Editing too soon seems to trigger a rebuild and throw polling out of whack. await setTimeout(3000); await appendToFile('src/main.ts', 'console.log(1);'); // We have to wait poll time + rebuild build time for the regex match. await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 14000); // No rebuilds should occur for a while await appendToFile('src/main.ts', 'console.log(1);'); await expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000)); // But a rebuild should happen roughly within the 10 second window. await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000); }
{ "end_byte": 1185, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/poll.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/disk-cache-purge.ts_0_950
import { join } from 'path'; import { createDir, expectFileNotToExist, expectFileToExist, writeFile } from '../../utils/fs'; import { silentNg } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; export default async function () { const cachePath = '.angular/cache'; const staleCachePath = join(cachePath, 'v1.0.0'); // No need to include all applications code to verify disk cache existence. await writeFile('src/main.ts', 'console.log(1);'); // Enable cache for all environments await updateJsonFile('angular.json', (config) => { config.cli ??= {}; config.cli.cache = { environment: 'all', enabled: true, path: cachePath, }; }); // Create a dummy stale disk cache directory. await createDir(staleCachePath); await expectFileToExist(staleCachePath); await silentNg('build'); await expectFileToExist(cachePath); await expectFileNotToExist(staleCachePath); }
{ "end_byte": 950, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/disk-cache-purge.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/chunk-optimizer.ts_0_664
import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { execWithEnv } from '../../utils/process'; /** * AOT builds with chunk optimizer should contain generated component definitions. * This is currently testing that the generated code is propagating through the * chunk optimization step. */ export default async function () { await execWithEnv('ng', ['build', '--output-hashing=none'], { ...process.env, NG_BUILD_OPTIMIZE_CHUNKS: '1', NG_BUILD_MANGLE: '0', }); const content = await readFile('dist/test-project/browser/main.js', 'utf-8'); assert.match(content, /\\u0275\\u0275defineComponent/); }
{ "end_byte": 664, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/chunk-optimizer.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/rebuild-replacements.ts_0_1401
import { getGlobalVariable } from '../../utils/env'; import { appendToFile, createDir, writeMultipleFiles } from '../../utils/fs'; import { waitForAnyProcessOutputToMatch } from '../../utils/process'; import { ngServe, updateJsonFile } from '../../utils/project'; const webpackGoodRegEx = getGlobalVariable('argv')['esbuild'] ? /Application bundle generation complete\./ : / Compiled successfully./; export default async function () { if (process.platform.startsWith('win')) { return; } await createDir('src/environments'); await writeMultipleFiles({ 'src/environments/environment.ts': `export const env = 'dev';`, 'src/environments/environment.prod.ts': `export const env = 'prod';`, 'src/main.ts': ` import { env } from './environments/environment'; console.log(env); `, }); await updateJsonFile('angular.json', (workspaceJson) => { const appArchitect = workspaceJson.projects['test-project'].architect; appArchitect.build.configurations.production.fileReplacements = [ { replace: 'src/environments/environment.ts', with: 'src/environments/environment.prod.ts', }, ]; }); await ngServe('--configuration=production'); // Should trigger a rebuild. await appendToFile('src/environments/environment.prod.ts', `console.log('PROD');`); await waitForAnyProcessOutputToMatch(webpackGoodRegEx); }
{ "end_byte": 1401, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/rebuild-replacements.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/rebuild-symlink.ts_0_1409
import { symlink } from 'fs/promises'; import { resolve } from 'path'; import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs'; import { execAndWaitForOutputToMatch, waitForAnyProcessOutputToMatch } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; import { getGlobalVariable } from '../../utils/env'; const buildReadyRegEx = getGlobalVariable('argv')['esbuild'] ? /Application bundle generation complete\./ : /Build at: /; export default async function () { // TODO: Disabled pending investigation. Steps work outside of test if (getGlobalVariable('argv')['esbuild']) { return; } await updateJsonFile('angular.json', (configJson) => { configJson.projects['test-project'].architect.build.options.preserveSymlinks = true; }); await writeMultipleFiles({ 'src/link-source.ts': '// empty file', 'src/main.ts': `import './link-dest';`, }); await symlink(resolve('src/link-source.ts'), resolve('src/link-dest.ts')); await execAndWaitForOutputToMatch( 'ng', ['build', '--watch', '--configuration=development'], buildReadyRegEx, ); // Trigger a rebuild await Promise.all([ waitForAnyProcessOutputToMatch(buildReadyRegEx), appendToFile('src/link-source.ts', `\nconsole.log('foo-bar');`), ]); await expectFileToMatch('dist/test-project/browser/main.js', `console.log('foo-bar')`); }
{ "end_byte": 1409, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/rebuild-symlink.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts_0_536
import { join } from 'path'; import { execWithEnv } from '../../utils/process'; export default async function () { // TODO(bazel): fails with bazel on windows if (process.platform.startsWith('win')) { return; } // Set the esbuild native binary path to a non-existent file to simulate a spawn error. // The build should still succeed by falling back to the WASM variant of esbuild. await execWithEnv('ng', ['build'], { ...process.env, 'ESBUILD_BINARY_PATH': join(__dirname, 'esbuild-bin-no-exist-xyz'), }); }
{ "end_byte": 536, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/assets.ts_0_1848
import * as fs from 'fs'; import { expectFileToExist, expectFileToMatch, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; import { expectToFail } from '../../utils/utils'; export default async function () { await writeFile('public/.file', ''); await writeFile('public/test.abc', 'hello world'); await ng('build', '--configuration=development'); await expectFileToExist('dist/test-project/browser/favicon.ico'); await expectFileToExist('dist/test-project/browser/.file'); await expectFileToMatch('dist/test-project/browser/test.abc', 'hello world'); await expectToFail(() => expectFileToExist('dist/test-project/browser/.gitkeep')); // Ensure `followSymlinks` option follows symlinks await updateJsonFile('angular.json', (workspaceJson) => { const appArchitect = workspaceJson.projects['test-project'].architect; appArchitect['build'].options.assets = [ { glob: '**/*', input: 'public', followSymlinks: true }, ]; }); fs.mkdirSync('dirToSymlink/subdir1', { recursive: true }); fs.mkdirSync('dirToSymlink/subdir2/subsubdir1', { recursive: true }); fs.writeFileSync('dirToSymlink/a.txt', ''); fs.writeFileSync('dirToSymlink/subdir1/b.txt', ''); fs.writeFileSync('dirToSymlink/subdir2/c.txt', ''); fs.writeFileSync('dirToSymlink/subdir2/subsubdir1/d.txt', ''); fs.symlinkSync(process.cwd() + '/dirToSymlink', 'public/symlinkDir'); await ng('build', '--configuration=development'); await expectFileToExist('dist/test-project/browser/symlinkDir/a.txt'); await expectFileToExist('dist/test-project/browser/symlinkDir/subdir1/b.txt'); await expectFileToExist('dist/test-project/browser/symlinkDir/subdir2/c.txt'); await expectFileToExist('dist/test-project/browser/symlinkDir/subdir2/subsubdir1/d.txt'); }
{ "end_byte": 1848, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/assets.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/disk-cache.ts_0_1811
import { expectFileNotToExist, expectFileToExist, rimraf, writeFile } from '../../utils/fs'; import { silentNg } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; const defaultCachePath = '.angular/cache'; const overriddenCachePath = '.cache/angular-cli'; export default async function () { const originalCIValue = process.env['CI']; // No need to include all applications code to verify disk cache existence. await writeFile('src/main.ts', 'console.log(1);'); try { // Should be enabled by default. process.env['CI'] = '0'; await configureAndRunTest(); // Should not write cache when it's disabled await configureAndRunTest({ enabled: false }); await expectFileNotToExist(defaultCachePath); // Should not write cache by default when in CI. process.env['CI'] = '1'; await configureAndRunTest(); await expectFileNotToExist(defaultCachePath); // Should write cache when it's enabled and 'environment' is set to 'all' or 'ci'. await configureAndRunTest({ environment: 'all' }); await expectFileToExist(defaultCachePath); // Should write cache to custom path when configured. await configureAndRunTest({ environment: 'ci', path: overriddenCachePath }); await expectFileNotToExist(defaultCachePath); await expectFileToExist(overriddenCachePath); } finally { process.env['CI'] = originalCIValue; } } async function configureAndRunTest(cacheOptions?: { environment?: 'ci' | 'local' | 'all'; enabled?: boolean; path?: string; }): Promise<void> { await Promise.all([ rimraf(overriddenCachePath), rimraf(defaultCachePath), updateJsonFile('angular.json', (config) => { config.cli ??= {}; config.cli.cache = cacheOptions; }), ]); await silentNg('build'); }
{ "end_byte": 1811, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/disk-cache.ts" }
angular-cli/tests/legacy-cli/e2e/tests/build/css-urls.ts_0_7116
import { ng } from '../../utils/process'; import { expectFileToMatch, expectFileToExist, expectFileMatchToExist, writeMultipleFiles, } from '../../utils/fs'; import { copyProjectAsset } from '../../utils/assets'; import { expectToFail } from '../../utils/utils'; import { getGlobalVariable } from '../../utils/env'; import { mkdir } from 'node:fs/promises'; const imgSvg = ` <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"> <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" /> </svg> `; export default async function () { const usingWebpack = !getGlobalVariable('argv')['esbuild']; const mediaPath = usingWebpack ? './dist/test-project/browser' : './dist/test-project/browser/media'; await mkdir('public/assets/', { recursive: true }); await Promise.resolve() // Verify absolute/relative paths in global/component css. .then(() => writeMultipleFiles({ 'src/styles.css': ` h1 { background: url('/assets/global-img-absolute.svg'); } h2 { background: url('./assets/global-img-relative.png'); } `, 'src/app/app.component.css': ` h3 { background: url('/assets/component-img-absolute.svg'); } h4 { background: url('../assets/component-img-relative.png'); } `, 'public/assets/global-img-absolute.svg': imgSvg, 'public/assets/component-img-absolute.svg': imgSvg, }), ) .then(() => copyProjectAsset('images/spectrum.png', './src/assets/global-img-relative.png')) .then(() => copyProjectAsset('images/spectrum.png', './src/assets/component-img-relative.png')) .then(() => ng('build', '--aot', '--configuration=development')) // Check paths are correctly generated. .then(() => expectFileToMatch('dist/test-project/browser/styles.css', 'assets/global-img-absolute.svg'), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', /url\((['"]?)\/assets\/global-img-absolute\.svg\1\)/, ), ) .then(() => expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/), ) .then(() => expectFileToMatch('dist/test-project/browser/main.js', '/assets/component-img-absolute.svg'), ) .then(() => expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/), ) // Check files are correctly created. .then(() => expectToFail(() => expectFileToExist(`${mediaPath}/global-img-absolute.svg`))) .then(() => expectToFail(() => expectFileToExist(`${mediaPath}/component-img-absolute.svg`))) .then(() => expectFileMatchToExist(mediaPath, /global-img-relative\.png/)) .then(() => expectFileMatchToExist(mediaPath, /component-img-relative\.png/)); // Early exit before deploy url tests if (!usingWebpack) { return; } // Check urls with deploy-url scheme are used as is. return ( Promise.resolve() .then(() => ng( 'build', '--base-href=/base/', '--deploy-url=http://deploy.url/', '--configuration=development', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', /url\(\'\/assets\/global-img-absolute\.svg\'\)/, ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', /url\(\'\/assets\/component-img-absolute\.svg\'\)/, ), ) // Check urls with base-href scheme are used as is (with deploy-url). .then(() => ng( 'build', '--base-href=http://base.url/', '--deploy-url=deploy/', '--configuration=development', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', /url\(\'\/assets\/global-img-absolute\.svg\'\)/, ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', /url\(\'\/assets\/component-img-absolute\.svg\'\)/, ), ) // Check urls with deploy-url and base-href scheme only use deploy-url. .then(() => ng( 'build', '--base-href=http://base.url/', '--deploy-url=http://deploy.url/', '--configuration=development', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', /url\(\'\/assets\/global-img-absolute\.svg\'\)/, ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', /url\(\'\/assets\/component-img-absolute\.svg\'\)/, ), ) // Check with base-href and deploy-url flags. .then(() => ng( 'build', '--base-href=/base/', '--deploy-url=deploy/', '--aot', '--configuration=development', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', '/assets/global-img-absolute.svg', ), ) .then(() => expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', '/assets/component-img-absolute.svg', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', /deploy\/component-img-relative\.png/, ), ) // Check with identical base-href and deploy-url flags. .then(() => ng( 'build', '--base-href=/base/', '--deploy-url=/base/', '--aot', '--configuration=development', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', '/assets/global-img-absolute.svg', ), ) .then(() => expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', '/assets/component-img-absolute.svg', ), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', /\/base\/component-img-relative\.png/, ), ) // Check with only base-href flag. .then(() => ng('build', '--base-href=/base/', '--aot', '--configuration=development')) .then(() => expectFileToMatch( 'dist/test-project/browser/styles.css', '/assets/global-img-absolute.svg', ), ) .then(() => expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/), ) .then(() => expectFileToMatch( 'dist/test-project/browser/main.js', '/assets/component-img-absolute.svg', ), ) .then(() => expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/), ) ); }
{ "end_byte": 7116, "start_byte": 0, "url": "https://github.com/angular/angular-cli/blob/main/tests/legacy-cli/e2e/tests/build/css-urls.ts" }