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 4fd19b4

Browse filesBrowse files
Run tests against both csproj and project.json-style projects. Assumes relevant dotnet SDKs are installed locally.
1 parent f34eb58 commit 4fd19b4
Copy full SHA for 4fd19b4

File tree

Expand file treeCollapse file tree

1 file changed

+84
-79
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+84
-79
lines changed
Open diff view settings
Collapse file

‎test/templates/angular.spec.ts‎

Copy file name to clipboardExpand all lines: test/templates/angular.spec.ts
+84-79Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,97 +5,102 @@ import { generateProjectSync } from './util/yeoman';
55
import { AspNetProcess, AspNetCoreEnviroment, defaultUrl, publishProjectSync } from './util/aspnet';
66
import { getValue, getCssPropertyValue } from './util/webdriverio';
77

8-
// First, generate a new project using the locally-built generator-aspnetcore-spa
9-
// Do this outside the Mocha fixture, otherwise Mocha will time out
10-
const appDir = path.resolve(__dirname, '../generated/angular');
11-
const publishedAppDir = path.resolve(appDir, './bin/Release/published');
12-
if (!process.env.SKIP_PROJECT_GENERATION) {
13-
generateProjectSync(appDir, {
14-
framework: 'angular-2',
15-
name: 'Test App',
16-
sdkVersion: '1.0.0-preview2-1-003177',
17-
tests: false
18-
});
19-
publishProjectSync(appDir, publishedAppDir);
20-
}
21-
22-
function testBasicNavigation() {
23-
describe('Basic navigation', () => {
24-
beforeEach(() => browser.url(defaultUrl));
25-
26-
it('should initially display the home page', () => {
27-
expect(browser.getText('h1')).to.eq('Hello, world!');
28-
expect(browser.getText('li a[href="https://angular.io/"]')).to.eq('Angular 2');
8+
// Currently we test both 'csproj' and 'project.json' project types. Eventually we'll only need csproj.
9+
['csproj', 'projectjson'].forEach(toolingType => {
10+
// First, generate a new project using the locally-built generator-aspnetcore-spa
11+
// Do this outside the Mocha fixture, otherwise Mocha will time out
12+
const appDir = path.resolve(__dirname, '../generated/angular', toolingType);
13+
const publishedAppDir = path.resolve(appDir, './bin/Release/published');
14+
if (!process.env.SKIP_PROJECT_GENERATION) {
15+
generateProjectSync(appDir, {
16+
framework: 'angular-2',
17+
name: 'Test App',
18+
sdkVersion: toolingType === 'projectjson' ? '1.0.0-preview2-1-003177' : '1.0.0-preview3-004056',
19+
tests: false
2920
});
30-
31-
it('should be able to show the counter page', () => {
32-
browser.click('a[href="/counter"]');
33-
expect(browser.getText('h1')).to.eq('Counter');
34-
35-
// Test clicking the 'increment' button
36-
expect(browser.getText('counter strong')).to.eq('0');
37-
browser.click('counter button');
38-
expect(browser.getText('counter strong')).to.eq('1');
39-
});
40-
41-
it('should be able to show the fetchdata page', () => {
42-
browser.click('a[href="/fetch-data"]');
43-
expect(browser.getText('h1')).to.eq('Weather forecast');
44-
45-
browser.waitForExist('fetchdata table');
46-
expect(getValue(browser.elements('fetchdata table tbody tr')).length).to.eq(5);
21+
publishProjectSync(appDir, publishedAppDir);
22+
}
23+
24+
function testBasicNavigation() {
25+
describe('Basic navigation', () => {
26+
beforeEach(() => browser.url(defaultUrl));
27+
28+
it('should initially display the home page', () => {
29+
expect(browser.getText('h1')).to.eq('Hello, world!');
30+
expect(browser.getText('li a[href="https://angular.io/"]')).to.eq('Angular 2');
31+
});
32+
33+
it('should be able to show the counter page', () => {
34+
browser.click('a[href="/counter"]');
35+
expect(browser.getText('h1')).to.eq('Counter');
36+
37+
// Test clicking the 'increment' button
38+
expect(browser.getText('counter strong')).to.eq('0');
39+
browser.click('counter button');
40+
expect(browser.getText('counter strong')).to.eq('1');
41+
});
42+
43+
it('should be able to show the fetchdata page', () => {
44+
browser.click('a[href="/fetch-data"]');
45+
expect(browser.getText('h1')).to.eq('Weather forecast');
46+
47+
browser.waitForExist('fetchdata table');
48+
expect(getValue(browser.elements('fetchdata table tbody tr')).length).to.eq(5);
49+
});
4750
});
48-
});
49-
}
51+
}
5052

51-
function testHotModuleReplacement() {
52-
describe('Hot module replacement', () => {
53-
beforeEach(() => browser.url(defaultUrl));
53+
function testHotModuleReplacement() {
54+
describe('Hot module replacement', () => {
55+
beforeEach(() => browser.url(defaultUrl));
5456

55-
it('should update when HTML is changed', () => {
56-
expect(browser.getText('h1')).to.eq('Hello, world!');
57+
it('should update when HTML is changed', () => {
58+
expect(browser.getText('h1')).to.eq('Hello, world!');
5759

58-
const filePath = path.resolve(appDir, './ClientApp/app/components/home/home.component.html');
59-
const origFileContents = fs.readFileSync(filePath, 'utf8');
60+
const filePath = path.resolve(appDir, './ClientApp/app/components/home/home.component.html');
61+
const origFileContents = fs.readFileSync(filePath, 'utf8');
6062

61-
try {
62-
const newFileContents = origFileContents.replace('<h1>Hello, world!</h1>', '<h1>HMR is working</h1>');
63-
fs.writeFileSync(filePath, newFileContents, { encoding: 'utf8' });
63+
try {
64+
const newFileContents = origFileContents.replace('<h1>Hello, world!</h1>', '<h1>HMR is working</h1>');
65+
fs.writeFileSync(filePath, newFileContents, { encoding: 'utf8' });
6466

65-
browser.waitUntil(() => browser.getText('h1').toString() === 'HMR is working');
66-
} finally {
67-
// Restore old contents so that other tests don't have to account for this
68-
fs.writeFileSync(filePath, origFileContents, { encoding: 'utf8' });
69-
}
70-
});
67+
browser.waitUntil(() => browser.getText('h1').toString() === 'HMR is working');
68+
} finally {
69+
// Restore old contents so that other tests don't have to account for this
70+
fs.writeFileSync(filePath, origFileContents, { encoding: 'utf8' });
71+
}
72+
});
7173

72-
it('should update when CSS is changed', () => {
73-
expect(getCssPropertyValue(browser, 'li.link-active a', 'color')).to.eq('rgba(255,255,255,1)');
74+
it('should update when CSS is changed', () => {
75+
expect(getCssPropertyValue(browser, 'li.link-active a', 'color')).to.eq('rgba(255,255,255,1)');
7476

75-
const filePath = path.resolve(appDir, './ClientApp/app/components/navmenu/navmenu.component.css');
76-
const origFileContents = fs.readFileSync(filePath, 'utf8');
77+
const filePath = path.resolve(appDir, './ClientApp/app/components/navmenu/navmenu.component.css');
78+
const origFileContents = fs.readFileSync(filePath, 'utf8');
7779

78-
try {
79-
const newFileContents = origFileContents.replace('color: white;', 'color: purple;');
80-
fs.writeFileSync(filePath, newFileContents, { encoding: 'utf8' });
80+
try {
81+
const newFileContents = origFileContents.replace('color: white;', 'color: purple;');
82+
fs.writeFileSync(filePath, newFileContents, { encoding: 'utf8' });
8183

82-
browser.waitUntil(() => getCssPropertyValue(browser, 'li.link-active a', 'color') === 'rgba(128,0,128,1)');
83-
} finally {
84-
// Restore old contents so that other tests don't have to account for this
85-
fs.writeFileSync(filePath, origFileContents, { encoding: 'utf8' });
86-
}
84+
browser.waitUntil(() => getCssPropertyValue(browser, 'li.link-active a', 'color') === 'rgba(128,0,128,1)');
85+
} finally {
86+
// Restore old contents so that other tests don't have to account for this
87+
fs.writeFileSync(filePath, origFileContents, { encoding: 'utf8' });
88+
}
89+
});
8790
});
88-
});
89-
}
91+
}
9092

91-
// Now launch dotnet and use selenium to perform tests
92-
describe('Angular template: dev mode', () => {
93-
AspNetProcess.RunInMochaContext(appDir, AspNetCoreEnviroment.development);
94-
testBasicNavigation();
95-
testHotModuleReplacement();
96-
});
93+
// Now launch dotnet and use selenium to perform tests
94+
describe('Angular template: dev mode', () => {
95+
AspNetProcess.RunInMochaContext(appDir, AspNetCoreEnviroment.development);
96+
testBasicNavigation();
97+
testHotModuleReplacement();
98+
});
9799

98-
describe('Angular template: production mode', () => {
99-
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, 'angular.dll');
100-
testBasicNavigation();
100+
describe('Angular template: production mode', () => {
101+
// csproj tooling takes the assembly name from <name>.csproj, whereas project.json takes it from the directory name
102+
const assemblyName = toolingType === 'csproj' ? 'TestApp.dll' : 'projectjson.dll';
103+
AspNetProcess.RunInMochaContext(publishedAppDir, AspNetCoreEnviroment.production, assemblyName);
104+
testBasicNavigation();
105+
});
101106
});

0 commit comments

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