-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests for default webpack package config
Adds a root module to the npm pacakge to make it possible to customize the RAILS_ROOT location. Supporting this approach means ensuring that relative paths for various Webpack configuration items resolve relative to the given root if it exists.
- Loading branch information
Showing
8 changed files
with
172 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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', () => { | ||
let environment; | ||
|
||
describe('toWebpackConfig', () => { | ||
beforeEach(() => { | ||
environment = new Environment() | ||
}) | ||
|
||
test('should return entry', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.entry.application).toEqual(resolve('test', 'test_app', '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('test', 'test_app', '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([join('test', 'test_app','node_modules')]) | ||
}) | ||
|
||
test('should return default resolve.modules with additions', () => { | ||
const config = environment.toWebpackConfig() | ||
expect(config.resolve.modules).toEqual([ | ||
resolve('test', 'test_app', 'app', 'javascript'), | ||
join('test', 'test_app', 'node_modules'), | ||
resolve('test', 'test_app', '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
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,11 @@ | ||
const { resolve, join } = require('path') | ||
const root = process.env.RAILS_ROOT || ''; | ||
const resolveRoot = (first, ...args) => first.startsWith('/') | ||
? join(first, ...args) | ||
: resolve(root, first, ...args) | ||
|
||
|
||
module.exports = { | ||
root, | ||
resolveRoot | ||
} |
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