Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd9ad38

Browse filesBrowse files
Run tests against 'dotnet new' output instead of Yeoman output
1 parent e057cb3 commit cd9ad38
Copy full SHA for cd9ad38

File tree

Expand file treeCollapse file tree

4 files changed

+75
-62
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+75
-62
lines changed
Open diff view settings
Collapse file

‎test/package.json‎

Copy file name to clipboardExpand all lines: test/package.json
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"selenium-standalone": "^5.9.0",
2424
"tree-kill": "^1.1.0",
2525
"typescript": "^2.1.4",
26-
"webdriverio": "^4.5.0",
27-
"yo": "^1.8.5"
26+
"webdriverio": "^4.5.0"
2827
},
2928
"devDependencies": {
3029
"wdio-junit-reporter": "^0.2.0",
Collapse file

‎test/templates/angular.spec.ts‎

Copy file name to clipboardExpand all lines: test/templates/angular.spec.ts
+11-8Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import * as rimraf from 'rimraf';
34
import { expect } from 'chai';
4-
import { generateProjectSync } from './util/yeoman';
5+
import { generateProjectSync } from './util/dotnetnew';
56
import { AspNetProcess, AspNetCoreEnviroment, defaultUrl, publishProjectSync } from './util/aspnet';
67
import { getValue, getCssPropertyValue } from './util/webdriverio';
78

8-
// First, generate a new project using the locally-built generator-aspnetcore-spa
9+
// First, generate a new project using the locally-built templates package
910
// Do this outside the Mocha fixture, otherwise Mocha will time out
1011
const appDir = path.resolve(__dirname, '../generated/angular');
1112
const publishedAppDir = path.resolve(appDir, './bin/Release/published');
13+
const publishedAppDllName = path.basename(appDir) + '.dll';
1214
if (!process.env.SKIP_PROJECT_GENERATION) {
13-
generateProjectSync(appDir, {
14-
framework: 'angular',
15-
name: 'Test App',
16-
tests: true
17-
});
15+
generateProjectSync(appDir, 'angular');
1816
publishProjectSync(appDir, publishedAppDir);
17+
18+
// Clear out any artifacts produced during publishing so they don't affect
19+
// the dev-mode application
20+
rimraf.sync(path.join(appDir, 'ClientApp/dist'));
21+
rimraf.sync(path.join(appDir, 'wwwroot/dist'));
1922
}
2023

2124
function testBasicNavigation() {
@@ -95,6 +98,6 @@ describe('Angular template: dev mode', () => {
9598
});
9699

97100
describe('Angular template: production mode', () => {
98-
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, 'TestApp.dll');
101+
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, publishedAppDllName);
99102
testBasicNavigation();
100103
});
Collapse file

‎test/templates/util/dotnetnew.ts‎

Copy file name to clipboard
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import * as childProcess from 'child_process';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import * as rimraf from 'rimraf';
5+
import * as mkdirp from 'mkdirp';
6+
7+
const templatePackageName = 'Microsoft.DotNet.Web.Spa.ProjectTemplates';
8+
const templatePackageArtifactsDir = '../templates/package-builder/dist/artifacts';
9+
10+
export function generateProjectSync(targetDir: string, templateName: string) {
11+
installTemplatePackage(targetDir, templatePackageName, templateName);
12+
executeDotNetNewTemplateSync(targetDir, templateName);
13+
executeCommand('npm install', /* quiet */ false, targetDir);
14+
}
15+
16+
function installTemplatePackage(targetDir: string, packageName: string, templateName: string) {
17+
// First figure out which file is the latest one for this package
18+
const packagePaths = fs.readdirSync(templatePackageArtifactsDir)
19+
.filter(name => name.startsWith(templatePackageName + '.'))
20+
.filter(name => path.extname(name) === '.nupkg')
21+
.map(name => path.join(templatePackageArtifactsDir, name))
22+
.sort();
23+
const latestPackagePath = packagePaths[packagePaths.length - 1];
24+
25+
if (!latestPackagePath) {
26+
throw new Error(`Could not find ${packageName}.*.nupkg in directory ${templatePackageArtifactsDir}`);
27+
}
28+
29+
// Uninstall any older version so we can be sure the new one did install
30+
try {
31+
console.log(`Uninstalling any prior version of ${packageName}...`);
32+
executeCommand(`dotnet new --uninstall ${packageName}`, /* quiet */ true);
33+
} catch (ex) {
34+
// Either no prior version existed, or we failed to uninstall. We'll determine
35+
// which it was next.
36+
}
37+
try {
38+
console.log(`Verifying that no prior version of ${packageName} is still installed...`);
39+
executeDotNetNewTemplateSync(targetDir, templateName, /* quiet */ true);
40+
throw new Error(`Failed to uninstall template package ${packageName}. The template '${templateName}' was not removed as expected.`);
41+
} catch (ex) {
42+
// Looks like we successfully uninstalled it
43+
console.log(`Confirmed that no prior version of ${templatePackageName} remains installed.`);
44+
}
45+
46+
// Now install the new version
47+
console.log(`Installing new templates package at ${latestPackagePath}...`);
48+
executeCommand(`dotnet new --install ${latestPackagePath}`, /* quiet */ true);
49+
}
50+
51+
function executeDotNetNewTemplateSync(targetDir: string, templateName: string, quiet?: boolean) {
52+
rimraf.sync(targetDir);
53+
mkdirp.sync(targetDir);
54+
executeCommand(`dotnet new ${templateName}`, quiet, targetDir);
55+
}
56+
57+
function executeCommand(command: string, quiet?: boolean, cwd?: string) {
58+
childProcess.execSync(command, {
59+
cwd,
60+
stdio: quiet ? null : 'inherit',
61+
encoding: 'utf8'
62+
});
63+
}
Collapse file

‎test/templates/util/yeoman.ts‎

Copy file name to clipboardExpand all lines: test/templates/util/yeoman.ts
-52Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.