Skip to content

Commit

Permalink
test: Update e2e tests for new project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco authored and hansl committed Apr 3, 2018
1 parent 8cb2376 commit d4f53c5
Show file tree
Hide file tree
Showing 113 changed files with 360 additions and 366 deletions.
5 changes: 1 addition & 4 deletions packages/@angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/
// @ignoreDep v8-profiler
import 'symbol-observable';
const isWarningEnabled = require('../utilities/config').isWarningEnabled;
const Version = require('../upgrade/version').Version;

const fs = require('fs');
const findUp = require('../utilities/find-up').findUp;
const packageJson = require('../package.json');
const path = require('path');
const resolve = require('resolve');
const stripIndents = require('common-tags').stripIndents;
const yellow = require('chalk').yellow;
const SemVer = require('semver').SemVer;
const semver = require('semver');
const events = require('events');


function _fromPackageJson(cwd?: string) {
cwd = cwd || process.cwd();

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/tests/basic/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function () {
// Add asset config in angular.json.
.then(() => updateJsonFile('angular.json', workspaceJson => {
const assets = [
{ 'glob': '**/*', 'input': 'projects/test-project/src/folder', 'output': 'folder' },
{ 'glob': '**/*', 'input': 'src/folder', 'output': 'folder' },
{ 'glob': 'glob-asset.txt' },
{ 'glob': 'output-asset.txt', 'output': 'output-folder' },
{ 'glob': '**/*', 'input': 'node_modules/some-package/', 'output': 'package-folder' }
Expand All @@ -111,7 +111,7 @@ export default function () {
.then(() => expectToFail(() => expectFileToExist('dist/assets/.gitkeep')))
// Update app to test assets are present.
.then(_ => !ejected && writeMultipleFiles({
'projects/test-project/src/app/app.module.ts': `
'src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
Expand All @@ -132,7 +132,7 @@ export default function () {
})
export class AppModule { }
`,
'projects/test-project/src/app/app.component.ts': `
'src/app/app.component.ts': `
import { Component } from '@angular/core';
import { Http, Response } from '@angular/http';
Expand All @@ -152,7 +152,7 @@ export default function () {
.subscribe(res => asset.content = res['_body']));
}
}`,
'projects/test-project/src/app/app.component.spec.ts': `
'src/app/app.component.spec.ts': `
import { TestBed, async } from '@angular/core/testing';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
Expand Down
28 changes: 14 additions & 14 deletions tests/e2e/tests/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ export default function () {
.then(() => ng('e2e', 'test-project-e2e'))
.then(() => ng('e2e', 'test-project-e2e', '--devServerTarget=test-project:serve:production'))
// Should accept different config file
.then(() => moveFile('./projects/test-project-e2e/protractor.conf.js',
'./projects/test-project-e2e/renamed-protractor.conf.js'))
.then(() => moveFile('./e2e/protractor.conf.js',
'./e2e/renamed-protractor.conf.js'))
.then(() => ng('e2e', 'test-project-e2e',
'--protractorConfig=projects/test-project-e2e/renamed-protractor.conf.js'))
.then(() => moveFile('./projects/test-project-e2e/renamed-protractor.conf.js', './projects/test-project-e2e/protractor.conf.js'))
'--protractorConfig=e2e/renamed-protractor.conf.js'))
.then(() => moveFile('./e2e/renamed-protractor.conf.js', './e2e/protractor.conf.js'))
// Should accept different multiple spec files
.then(() => moveFile('./projects/test-project-e2e/src/app.e2e-spec.ts',
'./projects/test-project-e2e/src/renamed-app.e2e-spec.ts'))
.then(() => copyFile('./projects/test-project-e2e/src/renamed-app.e2e-spec.ts',
'./projects/test-project-e2e/src/another-app.e2e-spec.ts'))
.then(() => moveFile('./e2e/src/app.e2e-spec.ts',
'./e2e/src/renamed-app.e2e-spec.ts'))
.then(() => copyFile('./e2e/src/renamed-app.e2e-spec.ts',
'./e2e/src/another-app.e2e-spec.ts'))
.then(() => ng('e2e', 'test-project-e2e', '--specs', './e2e/renamed-app.e2e-spec.ts',
'--specs', './e2e/another-app.e2e-spec.ts'))
// Rename the spec back to how it was.
.then(() => moveFile('./projects/test-project-e2e/src/renamed-app.e2e-spec.ts',
'./projects/test-project-e2e/src/app.e2e-spec.ts'))
.then(() => moveFile('./e2e/src/renamed-app.e2e-spec.ts',
'./e2e/src/app.e2e-spec.ts'))
// Suites block need to be added in the protractor.conf.js file to test suites
.then(() => replaceInFile('projects/test-project-e2e/protractor.conf.js', `allScriptsTimeout: 11000,`,
.then(() => replaceInFile('e2e/protractor.conf.js', `allScriptsTimeout: 11000,`,
`allScriptsTimeout: 11000,
suites: {
app: './projects/test-project-e2e/src/app.e2e-spec.ts'
app: './e2e/src/app.e2e-spec.ts'
},
`))
.then(() => ng('e2e', 'test-project-e2e', '--suite=app'))
// Remove suites block from protractor.conf.js file after testing suites
.then(() => replaceInFile('projects/test-project-e2e/protractor.conf.js', `allScriptsTimeout: 11000,
.then(() => replaceInFile('e2e/protractor.conf.js', `allScriptsTimeout: 11000,
suites: {
app: './projects/test-project-e2e/src/app.e2e-spec.ts'
app: './e2e/src/app.e2e-spec.ts'
},
`, `allScriptsTimeout: 11000,`
))
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/tests/basic/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function() {
// the file, otherwise rebuilds can be too fast and fail CI.
.then(() => Promise.all([
waitForAnyProcessOutputToMatch(validBundleRegEx, 10000),
writeFile('projects/test-project/src/app/app.module.ts', `
writeFile('src/app/app.module.ts', `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
Expand Down Expand Up @@ -68,7 +68,7 @@ export default function() {
.then(() => Promise.all([
waitForAnyProcessOutputToMatch(validBundleRegEx, 10000),
writeMultipleFiles({
'projects/test-project/src/app/app.module.ts': `
'src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
Expand All @@ -89,7 +89,7 @@ export default function() {
console.log('$$_E2E_GOLDEN_VALUE_1');
export let X = '$$_E2E_GOLDEN_VALUE_2';
`,
'projects/test-project/src/main.ts': `
'src/main.ts': `
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
Expand Down
46 changes: 23 additions & 23 deletions tests/e2e/tests/basic/scripts-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ import * as path from 'path';
// tslint:disable:max-line-length
export default function () {
return writeMultipleFiles({
'projects/test-project/src/string-script.js': 'console.log(\'string-script\'); var number = 1+1;',
'projects/test-project/src/zstring-script.js': 'console.log(\'zstring-script\');',
'projects/test-project/src/fstring-script.js': 'console.log(\'fstring-script\');',
'projects/test-project/src/ustring-script.js': 'console.log(\'ustring-script\');',
'projects/test-project/src/bstring-script.js': 'console.log(\'bstring-script\');',
'projects/test-project/src/astring-script.js': 'console.log(\'astring-script\');',
'projects/test-project/src/cstring-script.js': 'console.log(\'cstring-script\');',
'projects/test-project/src/input-script.js': 'console.log(\'input-script\');',
'projects/test-project/src/lazy-script.js': 'console.log(\'lazy-script\');',
'projects/test-project/src/pre-rename-script.js': 'console.log(\'pre-rename-script\');',
'projects/test-project/src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');'
'src/string-script.js': 'console.log(\'string-script\'); var number = 1+1;',
'src/zstring-script.js': 'console.log(\'zstring-script\');',
'src/fstring-script.js': 'console.log(\'fstring-script\');',
'src/ustring-script.js': 'console.log(\'ustring-script\');',
'src/bstring-script.js': 'console.log(\'bstring-script\');',
'src/astring-script.js': 'console.log(\'astring-script\');',
'src/cstring-script.js': 'console.log(\'cstring-script\');',
'src/input-script.js': 'console.log(\'input-script\');',
'src/lazy-script.js': 'console.log(\'lazy-script\');',
'src/pre-rename-script.js': 'console.log(\'pre-rename-script\');',
'src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');'
})
.then(() => appendToFile('projects/test-project/src/main.ts', 'import \'./string-script.js\';'))
.then(() => appendToFile('src/main.ts', 'import \'./string-script.js\';'))
.then(() => updateJsonFile('angular.json', configJson => {
const appArchitect = configJson.projects['test-project'].architect;
appArchitect.build.options.scripts = [
{ input: 'projects/test-project/src/string-script.js' },
{ input: 'projects/test-project/src/zstring-script.js' },
{ input: 'projects/test-project/src/fstring-script.js' },
{ input: 'projects/test-project/src/ustring-script.js' },
{ input: 'projects/test-project/src/bstring-script.js' },
{ input: 'projects/test-project/src/astring-script.js' },
{ input: 'projects/test-project/src/cstring-script.js' },
{ input: 'projects/test-project/src/input-script.js' },
{ input: 'projects/test-project/src/lazy-script.js', lazy: true },
{ input: 'projects/test-project/src/pre-rename-script.js', output: 'renamed-script' },
{ input: 'projects/test-project/src/pre-rename-lazy-script.js', output: 'renamed-lazy-script', lazy: true }
{ input: 'src/string-script.js' },
{ input: 'src/zstring-script.js' },
{ input: 'src/fstring-script.js' },
{ input: 'src/ustring-script.js' },
{ input: 'src/bstring-script.js' },
{ input: 'src/astring-script.js' },
{ input: 'src/cstring-script.js' },
{ input: 'src/input-script.js' },
{ input: 'src/lazy-script.js', lazy: true },
{ input: 'src/pre-rename-script.js', output: 'renamed-script' },
{ input: 'src/pre-rename-lazy-script.js', output: 'renamed-lazy-script', lazy: true }
];
}))
.then(() => ng('build', '--extract-css'))
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/tests/basic/styles-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { oneLineTrim } from 'common-tags';

export default function () {
return writeMultipleFiles({
'projects/test-project/src/string-style.css': '.string-style { color: red }',
'projects/test-project/src/input-style.css': '.input-style { color: red }',
'projects/test-project/src/lazy-style.css': '.lazy-style { color: red }',
'projects/test-project/src/pre-rename-style.css': '.pre-rename-style { color: red }',
'projects/test-project/src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }'
'src/string-style.css': '.string-style { color: red }',
'src/input-style.css': '.input-style { color: red }',
'src/lazy-style.css': '.lazy-style { color: red }',
'src/pre-rename-style.css': '.pre-rename-style { color: red }',
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }'
})
.then(() => updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.styles = [
{ input: 'projects/test-project/src/string-style.css' },
{ input: 'projects/test-project/src/input-style.css' },
{ input: 'projects/test-project/src/lazy-style.css', lazy: true },
{ input: 'projects/test-project/src/pre-rename-style.css', output: 'renamed-style' },
{ input: 'projects/test-project/src/pre-rename-lazy-style.css', output: 'renamed-lazy-style', lazy: true }
{ input: 'src/string-style.css' },
{ input: 'src/input-style.css' },
{ input: 'src/lazy-style.css', lazy: true },
{ input: 'src/pre-rename-style.css', output: 'renamed-style' },
{ input: 'src/pre-rename-lazy-style.css', output: 'renamed-lazy-style', lazy: true }
];
}))
.then(() => ng('build', '--extract-css'))
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/tests/basic/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { moveFile } from '../../utils/fs';
export default function () {
// make sure both --watch=false work
return ng('test', '--watch=false')
.then(() => moveFile('./projects/test-project/karma.conf.js',
'./projects/test-project/karma.conf.bis.js'))
.then(() => ng('test', '--watch=false', '--karmaConfig=projects/test-project/karma.conf.bis.js'));
.then(() => moveFile('./src/karma.conf.js',
'./src/karma.conf.bis.js'))
.then(() => ng('test', '--watch=false', '--karmaConfig=src/karma.conf.bis.js'));
}
4 changes: 2 additions & 2 deletions tests/e2e/tests/build/allow-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { appendToFile, writeFile } from '../../utils/fs';
export default async function() {
// TODO(architect): Delete this test. It is now in devkit/build-angular.

await writeFile('projects/test-project/src/my-js-file.js', 'console.log(1); export const a = 2;');
await appendToFile('projects/test-project/src/main.ts', `
await writeFile('src/my-js-file.js', 'console.log(1); export const a = 2;');
await appendToFile('src/main.ts', `
import { a } from './my-js-file';
console.log(a);
`);
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/tests/build/aot/aot-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export default function() {
return;

return ng('generate', 'component', 'test-component', '--module', 'app.module.ts')
.then(() => prependToFile('projects/test-project/src/app/test-component/test-component.component.ts', `
.then(() => prependToFile('src/app/test-component/test-component.component.ts', `
import { Optional, SkipSelf } from '@angular/core';
`))
.then(() => replaceInFile('projects/test-project/src/app/test-component/test-component.component.ts',
.then(() => replaceInFile('src/app/test-component/test-component.component.ts',
/constructor.*/, `
constructor(@Optional() @SkipSelf() public test: TestComponentComponent) {
console.log(test);
}
`))
.then(() => appendToFile('projects/test-project/src/app/app.component.html', `
.then(() => appendToFile('src/app/app.component.html', `
<app-test-component></app-test-component>
`))
.then(() => ng('build', '--aot'))
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/tests/build/aot/aot-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function () {
// TODO(architect): Delete this test. It is now in devkit/build-angular.

return Promise.resolve()
.then(() => createDir('projects/test-project/src/locale'))
.then(() => writeFile('projects/test-project/src/locale/messages.fr.xlf', `
.then(() => createDir('src/locale'))
.then(() => writeFile('src/locale/messages.fr.xlf', `
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
Expand All @@ -23,19 +23,19 @@ export default function () {
</body>
</file>
</xliff>`))
.then(() => appendToFile('projects/test-project/src/app/app.component.html',
.then(() => appendToFile('src/app/app.component.html',
'<h1 i18n="An introduction header for this sample">Hello i18n!</h1>'))
.then(() => ng('build', '--aot', '--i18n-file', 'projects/test-project/src/locale/messages.fr.xlf', '--i18n-format',
.then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format',
'xlf', '--i18n-locale', 'fr'))
.then(() => expectFileToMatch('dist/test-project/main.js', /Bonjour i18n!/))
.then(() => ng('build', '--aot'))
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /Bonjour i18n!/)))
.then(() => expectFileToMatch('dist/test-project/main.js', /Hello i18n!/))
.then(() => appendToFile('projects/test-project/src/app/app.component.html',
.then(() => appendToFile('src/app/app.component.html',
'<p i18n>Other content</p>'))
.then(() => ng('build', '--aot', '--i18nFile', 'projects/test-project/src/locale/messages.fr.xlf', '--i18nFormat',
.then(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', '--i18nFormat',
'xlf', '--i18n-locale', 'fr', '--i18n-missing-translation', 'ignore'))
.then(() => expectFileToMatch('dist/test-project/main.js', /Other content/))
.then(() => expectToFail(() => ng('build', '--aot', '--i18nFile', 'projects/test-project/src/locale/messages.fr.xlf',
.then(() => expectToFail(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf',
'--i18nFormat', 'xlf', '--i18n-locale', 'fr', '--i18n-missing-translation', 'error')));
}
2 changes: 1 addition & 1 deletion tests/e2e/tests/build/build-app-shell-with-schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function () {
.then(() => expectToFail(() => {
return ng('generate', 'appShell', '--universal-app', 'universal');
})
.then(() => appendToFile('projects/test-project/src/app/app.component.html', '<router-outlet></router-outlet>'))
.then(() => appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>'))
.then(() => ng('generate', 'appShell', '--universal-app', 'universal'))
.then(() => updateJsonFile('package.json', packageJson => {
const dependencies = packageJson['dependencies'];
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/tests/build/build-app-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default function () {
builder: '@angular-devkit/build-angular:server',
options: {
outputPath: 'dist/test-project-server',
main: 'projects/test-project/src/main.server.ts',
tsConfig: 'projects/test-project/tsconfig.server.json'
main: 'src/main.server.ts',
tsConfig: 'src/tsconfig.server.json'
}
};
appArchitect['app-shell'] = {
Expand All @@ -44,9 +44,9 @@ export default function () {
}
};
}))
.then(() => writeFile('./projects/test-project/tsconfig.server.json', `
.then(() => writeFile('./src/tsconfig.server.json', `
{
"extends": "../../tsconfig.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist-server",
"baseUrl": "./",
Expand All @@ -58,11 +58,11 @@ export default function () {
"**/*.spec.ts"
],
"angularCompilerOptions": {
"entryModule": "src/app/app.server.module#AppServerModule"
"entryModule": "app/app.server.module#AppServerModule"
}
}
`))
.then(() => writeFile('./projects/test-project/src/main.server.ts', `
.then(() => writeFile('./src/main.server.ts', `
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
Expand All @@ -73,11 +73,11 @@ export default function () {
export { AppServerModule } from './app/app.server.module';
`))
.then(() => writeFile('projects/test-project/src/app/app.component.html', stripIndent`
.then(() => writeFile('./src/app/app.component.html', stripIndent`
Hello World
<router-outlet></router-outlet>
`))
.then(() => writeFile('projects/test-project/src/app/app.module.ts', stripIndent`
.then(() => writeFile('./src/app/app.module.ts', stripIndent`
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
Expand All @@ -94,7 +94,7 @@ export default function () {
})
export class AppModule { }
`))
.then(() => writeFile('projects/test-project/src/app/app.server.module.ts', stripIndent`
.then(() => writeFile('./src/app/app.server.module.ts', stripIndent`
import {NgModule} from '@angular/core';
import {ServerModule} from '@angular/platform-server';
import { Routes, RouterModule } from '@angular/router';
Expand Down Expand Up @@ -122,7 +122,7 @@ export default function () {
})
export class AppServerModule {}
`))
.then(() => writeFile('projects/test-project/src/app/shell.component.ts', stripIndent`
.then(() => writeFile('./src/app/shell.component.ts', stripIndent`
import { Component } from '@angular/core';
@Component({
selector: 'app-shell',
Expand Down

0 comments on commit d4f53c5

Please sign in to comment.