-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serve assets
files from ng test
#3628
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are proxies always needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no karma expert and worked my way through trial and error really, but according to the docs and my tries, when you add a file to the
files
array, it gets served from/base/src/path-to-file
only. The proxy adds another endpoint (like a URL rewrite) from/path-to-file
to/base/src/path-to-file
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filipesilva I added a comment explaining why we need proxies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes sense to me. I remember a similar situation I ran into another project. Without the proxy, fetch would not work correctly.