mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Run tests against 'dotnet new' output instead of Yeoman output
This commit is contained in:
@@ -23,8 +23,7 @@
|
|||||||
"selenium-standalone": "^5.9.0",
|
"selenium-standalone": "^5.9.0",
|
||||||
"tree-kill": "^1.1.0",
|
"tree-kill": "^1.1.0",
|
||||||
"typescript": "^2.1.4",
|
"typescript": "^2.1.4",
|
||||||
"webdriverio": "^4.5.0",
|
"webdriverio": "^4.5.0"
|
||||||
"yo": "^1.8.5"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"wdio-junit-reporter": "^0.2.0",
|
"wdio-junit-reporter": "^0.2.0",
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { generateProjectSync } from './util/yeoman';
|
import { generateProjectSync } from './util/dotnetnew';
|
||||||
import { AspNetProcess, AspNetCoreEnviroment, defaultUrl, publishProjectSync } from './util/aspnet';
|
import { AspNetProcess, AspNetCoreEnviroment, defaultUrl, publishProjectSync } from './util/aspnet';
|
||||||
import { getValue, getCssPropertyValue } from './util/webdriverio';
|
import { getValue, getCssPropertyValue } from './util/webdriverio';
|
||||||
|
|
||||||
// First, generate a new project using the locally-built generator-aspnetcore-spa
|
// First, generate a new project using the locally-built templates package
|
||||||
// Do this outside the Mocha fixture, otherwise Mocha will time out
|
// Do this outside the Mocha fixture, otherwise Mocha will time out
|
||||||
const appDir = path.resolve(__dirname, '../generated/angular');
|
const appDir = path.resolve(__dirname, '../generated/angular');
|
||||||
const publishedAppDir = path.resolve(appDir, './bin/Release/published');
|
const publishedAppDir = path.resolve(appDir, './bin/Release/published');
|
||||||
|
const publishedAppDllName = path.basename(appDir) + '.dll';
|
||||||
if (!process.env.SKIP_PROJECT_GENERATION) {
|
if (!process.env.SKIP_PROJECT_GENERATION) {
|
||||||
generateProjectSync(appDir, {
|
generateProjectSync(appDir, 'angular');
|
||||||
framework: 'angular',
|
|
||||||
name: 'Test App',
|
|
||||||
tests: true
|
|
||||||
});
|
|
||||||
publishProjectSync(appDir, publishedAppDir);
|
publishProjectSync(appDir, publishedAppDir);
|
||||||
|
|
||||||
|
// Clear out any artifacts produced during publishing so they don't affect
|
||||||
|
// the dev-mode application
|
||||||
|
rimraf.sync(path.join(appDir, 'ClientApp/dist'));
|
||||||
|
rimraf.sync(path.join(appDir, 'wwwroot/dist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testBasicNavigation() {
|
function testBasicNavigation() {
|
||||||
@@ -95,6 +98,6 @@ describe('Angular template: dev mode', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Angular template: production mode', () => {
|
describe('Angular template: production mode', () => {
|
||||||
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, 'TestApp.dll');
|
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, publishedAppDllName);
|
||||||
testBasicNavigation();
|
testBasicNavigation();
|
||||||
});
|
});
|
||||||
63
test/templates/util/dotnetnew.ts
Normal file
63
test/templates/util/dotnetnew.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import * as childProcess from 'child_process';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
|
import * as mkdirp from 'mkdirp';
|
||||||
|
|
||||||
|
const templatePackageName = 'Microsoft.DotNet.Web.Spa.ProjectTemplates';
|
||||||
|
const templatePackageArtifactsDir = '../templates/package-builder/dist/artifacts';
|
||||||
|
|
||||||
|
export function generateProjectSync(targetDir: string, templateName: string) {
|
||||||
|
installTemplatePackage(targetDir, templatePackageName, templateName);
|
||||||
|
executeDotNetNewTemplateSync(targetDir, templateName);
|
||||||
|
executeCommand('npm install', /* quiet */ false, targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
function installTemplatePackage(targetDir: string, packageName: string, templateName: string) {
|
||||||
|
// First figure out which file is the latest one for this package
|
||||||
|
const packagePaths = fs.readdirSync(templatePackageArtifactsDir)
|
||||||
|
.filter(name => name.startsWith(templatePackageName + '.'))
|
||||||
|
.filter(name => path.extname(name) === '.nupkg')
|
||||||
|
.map(name => path.join(templatePackageArtifactsDir, name))
|
||||||
|
.sort();
|
||||||
|
const latestPackagePath = packagePaths[packagePaths.length - 1];
|
||||||
|
|
||||||
|
if (!latestPackagePath) {
|
||||||
|
throw new Error(`Could not find ${packageName}.*.nupkg in directory ${templatePackageArtifactsDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uninstall any older version so we can be sure the new one did install
|
||||||
|
try {
|
||||||
|
console.log(`Uninstalling any prior version of ${packageName}...`);
|
||||||
|
executeCommand(`dotnet new --uninstall ${packageName}`, /* quiet */ true);
|
||||||
|
} catch (ex) {
|
||||||
|
// Either no prior version existed, or we failed to uninstall. We'll determine
|
||||||
|
// which it was next.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(`Verifying that no prior version of ${packageName} is still installed...`);
|
||||||
|
executeDotNetNewTemplateSync(targetDir, templateName, /* quiet */ true);
|
||||||
|
throw new Error(`Failed to uninstall template package ${packageName}. The template '${templateName}' was not removed as expected.`);
|
||||||
|
} catch (ex) {
|
||||||
|
// Looks like we successfully uninstalled it
|
||||||
|
console.log(`Confirmed that no prior version of ${templatePackageName} remains installed.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now install the new version
|
||||||
|
console.log(`Installing new templates package at ${latestPackagePath}...`);
|
||||||
|
executeCommand(`dotnet new --install ${latestPackagePath}`, /* quiet */ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function executeDotNetNewTemplateSync(targetDir: string, templateName: string, quiet?: boolean) {
|
||||||
|
rimraf.sync(targetDir);
|
||||||
|
mkdirp.sync(targetDir);
|
||||||
|
executeCommand(`dotnet new ${templateName}`, quiet, targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
function executeCommand(command: string, quiet?: boolean, cwd?: string) {
|
||||||
|
childProcess.execSync(command, {
|
||||||
|
cwd,
|
||||||
|
stdio: quiet ? null : 'inherit',
|
||||||
|
encoding: 'utf8'
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import * as childProcess from 'child_process';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as rimraf from 'rimraf';
|
|
||||||
import * as mkdirp from 'mkdirp';
|
|
||||||
|
|
||||||
const generatorDirRelative = '../templates/package-builder/dist/generator-aspnetcore-spa';
|
|
||||||
const yoPackageDirAbsolute = path.resolve('./node_modules/yo');
|
|
||||||
|
|
||||||
export interface GeneratorOptions {
|
|
||||||
framework: string;
|
|
||||||
name: string;
|
|
||||||
tests?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateProjectSync(targetDir: string, generatorOptions: GeneratorOptions) {
|
|
||||||
const generatorDirAbsolute = path.resolve(generatorDirRelative);
|
|
||||||
console.log(`Running NPM install to prepare Yeoman generator at ${ generatorDirAbsolute }`);
|
|
||||||
childProcess.execSync(`npm install`, { stdio: 'inherit', cwd: generatorDirAbsolute });
|
|
||||||
|
|
||||||
console.log(`Ensuring empty output directory at ${ targetDir }`);
|
|
||||||
rimraf.sync(targetDir);
|
|
||||||
mkdirp.sync(targetDir);
|
|
||||||
|
|
||||||
const yoExecutableAbsolute = findYeomanCliScript();
|
|
||||||
console.log(`Will invoke Yeoman at ${ yoExecutableAbsolute } to generate application in ${ targetDir } with options:`);
|
|
||||||
console.log(JSON.stringify(generatorOptions, null, 2));
|
|
||||||
const command = `node "${ yoExecutableAbsolute }" "${ path.resolve(generatorDirAbsolute, './app/index.js') }"`;
|
|
||||||
const args = makeYeomanCommandLineArgs(generatorOptions);
|
|
||||||
childProcess.execSync(`${ command } ${ args }`, {
|
|
||||||
stdio: 'inherit',
|
|
||||||
cwd: targetDir
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function findYeomanCliScript() {
|
|
||||||
// On Windows, you can't invoke ./node_modules/.bin/yo from the shell for some reason.
|
|
||||||
// So instead, we'll locate the CLI entrypoint that yeoman would expose if it was installed globally.
|
|
||||||
const yeomanPackageJsonPath = path.join(yoPackageDirAbsolute, './package.json');
|
|
||||||
const yeomanPackageJson = require(yeomanPackageJsonPath);
|
|
||||||
const yeomanCliScriptRelative = yeomanPackageJson.bin.yo;
|
|
||||||
if (!yeomanCliScriptRelative) {
|
|
||||||
throw new Error(`Could not find Yeoman CLI script. Looked for a bin/yo entry in ${ yeomanPackageJsonPath }`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.join(yoPackageDirAbsolute, yeomanCliScriptRelative);
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeYeomanCommandLineArgs(generatorOptions: GeneratorOptions) {
|
|
||||||
return Object.getOwnPropertyNames(generatorOptions)
|
|
||||||
.map(key => `--${ key }="${ generatorOptions[key] }"`)
|
|
||||||
.join(' ');
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user