forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng test): serve
assets
files from ng test
closes angular#2803
- Loading branch information
Showing
2 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,65 @@ | ||
import {ng} from '../../utils/process'; | ||
import { writeMultipleFiles } from '../../utils/fs'; | ||
import { ng } from '../../utils/process'; | ||
import { updateJsonFile } from '../../utils/project'; | ||
import { expectToFail } from '../../utils/utils'; | ||
import { stripIndent } from 'common-tags'; | ||
|
||
|
||
export default function() { | ||
// make sure both --watch=false and --single-run work | ||
export default function () { | ||
// Each test function returns PromiseLike<Something_Different>, | ||
// which would throw normally | ||
// but resolve() normalizes this to <any> from the start | ||
return Promise.resolve() | ||
.then(() => testWatchFalseAndSingleRun()) | ||
.then(() => testAssetsAreServed()); | ||
} | ||
|
||
// Make sure both --watch=false and --single-run work | ||
function testWatchFalseAndSingleRun() { | ||
return ng('test', '--single-run') | ||
.then(() => ng('test', '--watch=false')); | ||
} | ||
|
||
// Make sure asset files are served | ||
function testAssetsAreServed() { | ||
return Promise.resolve() | ||
.then(() => writeMultipleFiles({ | ||
'src/assets/file.txt': 'assets-folder-content', | ||
'src/file.txt': 'file-content', | ||
// Not using `async()` in tests as it seemed to swallow `fetch()` errors | ||
'src/app/app.component.spec.ts': stripIndent` | ||
describe('Test Runner', () => { | ||
const fetch = global['fetch']; | ||
it('should serve files in assets folder', (done) => { | ||
fetch('/assets/file.txt') | ||
.then(response => response.text()) | ||
.then(fileText => { | ||
expect(fileText).toMatch('assets-folder-content'); | ||
done(); | ||
}); | ||
}); | ||
it('should serve files explicitly added to assets array', (done) => { | ||
fetch('/file.txt') | ||
.then(response => response.text()) | ||
.then(fileText => { | ||
expect(fileText).toMatch('file-content'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
` | ||
})) | ||
// Test failure condition (no assets in angular-cli.json) | ||
.then(() => updateJsonFile('angular-cli.json', configJson => { | ||
const app = configJson['apps'][0]; | ||
app['assets'] = []; | ||
})) | ||
.then(() => expectToFail(() => ng('test', '--single-run'), | ||
'Should fail because the assets to serve were not in the angular-cli config')) | ||
// Test passing condition (assets are included) | ||
.then(() => updateJsonFile('angular-cli.json', configJson => { | ||
const app = configJson['apps'][0]; | ||
app['assets'] = ['assets', 'file.txt']; | ||
})) | ||
.then(() => ng('test', '--single-run')); | ||
} |