-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adds tests for environment.toWebpackConfig #1099
Merged
gauravtiwari
merged 2 commits into
rails:master
from
rossta:add-environment-package-tests
Dec 15, 2017
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* global test expect, describe */ | ||
|
||
// environment.js expects to find config/webpacker.yml and resolved modules from | ||
// the root of a Rails project | ||
const cwd = process.cwd(); | ||
const chdirApp = () => process.chdir('test/test_app') | ||
const chdirCwd = () => process.chdir(cwd) | ||
chdirApp(); | ||
|
||
const { resolve, join } = require('path') | ||
const { sync } = require('glob') | ||
const assert = require('assert') | ||
|
||
const { ConfigList, ConfigObject } = require('../config_types') | ||
|
||
const Environment = require('../environment') | ||
|
||
describe('Environment', () => { | ||
afterAll(chdirCwd); | ||
|
||
let environment; | ||
|
||
describe('toWebpackConfig', () => { | ||
beforeEach(() => { | ||
environment = new Environment() | ||
}) | ||
|
||
test('should return entry', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.entry.application).toEqual(resolve('app', 'javascript', 'packs', 'application.js')) | ||
}) | ||
|
||
test('should return output', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.output.filename).toEqual('[name]-[chunkhash].js') | ||
expect(config.output.chunkFilename).toEqual('[name]-[chunkhash].chunk.js') | ||
expect(config.output.path).toEqual(resolve('public', 'packs-test')) | ||
expect(config.output.publicPath).toEqual('/packs-test/') | ||
}) | ||
|
||
test('should return default loader rules for each file in config/loaders', () => { | ||
const config = environment.toWebpackConfig() | ||
const rules = Object.keys(require('../rules')) | ||
const [{ oneOf: configRules }] = config.module.rules; | ||
|
||
expect(rules.length).toBeGreaterThan(1) | ||
expect(configRules.length).toEqual(rules.length) | ||
}) | ||
|
||
test('should return default plugins', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.plugins.length).toEqual(4) | ||
}) | ||
|
||
test('should return default resolveLoader', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.resolveLoader.modules).toEqual(['node_modules']) | ||
}) | ||
|
||
test('should return default resolve.modules with additions', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.resolve.modules).toEqual([ | ||
resolve('app', 'javascript'), | ||
'node_modules', | ||
'app/assets', | ||
'/etc/yarn', | ||
]) | ||
}) | ||
|
||
test('returns plugins property as Array', () => { | ||
const config = environment.toWebpackConfig() | ||
|
||
expect(config.plugins).toBeInstanceOf(Array) | ||
expect(config.plugins).not.toBeInstanceOf(ConfigList) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint no-console:0 */ | ||
// This file is automatically compiled by Webpack, along with any other files | ||
// present in this directory. You're encouraged to place your actual application logic in | ||
// a relevant structure within app/javascript and only use these pack files to reference | ||
// that code so it'll be compiled. | ||
// | ||
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate | ||
// layout file, like app/views/layouts/application.html.erb | ||
|
||
console.log('Hello World from Webpacker') |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default | ||
source_path: app/javascript | ||
source_entry_path: packs | ||
public_output_path: packs | ||
cache_path: tmp/cache/webpacker | ||
|
||
# Additional paths webpack should lookup modules | ||
# ['app/assets', 'engine/foo/app/assets'] | ||
resolved_paths: | ||
- app/assets | ||
- /etc/yarn | ||
|
||
# Reload manifest.json on all requests so we reload latest compiled packs | ||
cache_manifest: false | ||
|
||
extensions: | ||
- .coffee | ||
- .erb | ||
- .js | ||
- .jsx | ||
- .ts | ||
- .vue | ||
- .sass | ||
- .scss | ||
- .css | ||
- .png | ||
- .svg | ||
- .gif | ||
- .jpeg | ||
- .jpg | ||
|
||
development: | ||
<<: *default | ||
compile: true | ||
|
||
# Reference: https://webpack.js.org/configuration/dev-server/ | ||
dev_server: | ||
https: false | ||
host: localhost | ||
port: 3035 | ||
public: localhost:3035 | ||
hmr: false | ||
# Inline should be set to true if using HMR | ||
inline: true | ||
overlay: true | ||
disable_host_check: true | ||
use_local_ip: false | ||
|
||
test: | ||
<<: *default | ||
compile: true | ||
|
||
# Compile test packs to a separate directory | ||
public_output_path: packs-test | ||
|
||
production: | ||
<<: *default | ||
|
||
# Production depends on precompilation of packs prior to booting for performance. | ||
compile: false | ||
|
||
# Cache manifest.json for performance | ||
cache_manifest: true |
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.
Is this intentional?
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.
No, that was a debugging line that should be removed (and looks like you've done that on master already).