Skip to content

Commit 9906259

Browse files
committed
update test suite
1 parent fae9ba7 commit 9906259

15 files changed

+136
-279
lines changed

.github/workflows/ruby.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v3
2121
- uses: actions/setup-node@v3
22+
- run: npm -g install yalc
23+
- run: yalc publish
24+
- run: cd test/dummy_shakapacker && yalc add react_ujs
25+
- run: cd test/dummy_shakapacker && yarn
2226
- uses: ruby/setup-ruby@v1
2327
with:
2428
ruby-version: 2.7.3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ test/*/public/packs
77
**/node_modules
88
react-builds/build
99
coverage/
10+
**/.yalc
11+
**/yalc.*

Rakefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ namespace :ujs do
7070
end
7171
end
7272

73-
require 'rake/testtask'
73+
require "minitest/test_task"
7474

75-
Rake::TestTask.new(:test) do |t|
76-
t.libs << 'lib'
77-
t.libs << 'test'
78-
t.pattern = ENV['TEST_PATTERN'] || 'test/**/*_test.rb'
79-
t.verbose = ENV['TEST_VERBOSE'] == '1'
75+
Minitest::TestTask.create(:test) do |t|
76+
t.libs << "test"
77+
t.libs << "lib"
8078
t.warning = false
79+
t.test_globs = ENV['TEST_PATTERN'] || 'test/**/*_test.rb'
80+
t.verbose = ENV['TEST_VERBOSE'] == '1'
8181
end
8282

8383
task default: :test

test/dummy_shakapacker/babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = function (api) {
22
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
33
const resultConfig = defaultConfigFunc(api)
44
const isProductionEnv = api.env('production')
5+
const isDevelopmentEnv = api.env('development')
56

67
const changesOnDefault = {
78
presets: [
@@ -15,6 +16,12 @@ module.exports = function (api) {
1516
].filter(Boolean),
1617
plugins: [
1718
process.env.WEBPACK_SERVE && 'react-refresh/babel',
19+
!isDevelopmentEnv && [
20+
'babel-plugin-transform-react-remove-prop-types',
21+
{
22+
removeImport: true,
23+
},
24+
],
1825
].filter(Boolean),
1926
}
2027

test/dummy_shakapacker/bin/webpack

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/dummy_shakapacker/bin/webpack-dev-server

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/dummy_shakapacker/bin/webpacker

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
3+
require "pathname"
4+
require "bundler/setup"
5+
require "webpacker"
6+
require "webpacker/webpack_runner"
7+
8+
ENV["RAILS_ENV"] ||= "development"
9+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
10+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
11+
12+
APP_ROOT = File.expand_path("..", __dir__)
13+
Dir.chdir(APP_ROOT) do
14+
Webpacker::WebpackRunner.run(ARGV)
15+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= "development"
4+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "bundler/setup"
11+
12+
require "webpacker"
13+
require "webpacker/dev_server_runner"
14+
15+
APP_ROOT = File.expand_path("..", __dir__)
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::DevServerRunner.run(ARGV)
18+
end

test/dummy_shakapacker/config/webpack/clientWebpackConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const configureClient = () => {
77
// In case this entry is not deleted, a very strange "window" not found
88
// error shows referring to window["webpackJsonp"]. That is because the
99
// client config is going to try to load chunks.
10-
delete clientConfig.entry['server-bundle']
10+
delete clientConfig.entry['server_rendering']
1111

1212
return clientConfig
1313
}

test/dummy_shakapacker/config/webpack/serverWebpackConfig.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const configureServer = () => {
1212

1313
// We just want the single server bundle entry
1414
const serverEntry = {
15-
'server-bundle': serverWebpackConfig.entry['server-bundle']
15+
'server_rendering': serverWebpackConfig.entry['server_rendering']
1616
}
1717

18-
if (!serverEntry['server-bundle']) {
19-
throw new Error('Create a pack with the file name \'server-bundle.js\' containing all the server rendering files')
18+
if (!serverEntry['server_rendering']) {
19+
throw new Error('Create a pack with the file name \'server_rendering.js\' containing all the server rendering files')
2020
}
2121

2222
serverWebpackConfig.entry = serverEntry
@@ -41,10 +41,10 @@ const configureServer = () => {
4141
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
4242
)
4343

44-
// Custom output for the server-bundle that matches the config in
44+
// Custom output for the server_rendering that matches the config in
4545
// config/initializers/react_on_rails.rb
4646
serverWebpackConfig.output = {
47-
filename: 'server-bundle.js',
47+
filename: 'server_rendering.js',
4848
globalObject: 'this',
4949
// If using the React on Rails Pro node server renderer, uncomment the next line
5050
// libraryTarget: 'commonjs2',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { env, webpackConfig } = require('shakapacker');
2+
const { existsSync } = require('fs');
3+
const { resolve } = require('path');
4+
5+
const envSpecificConfig = () => {
6+
const path = resolve(__dirname, `${env.nodeEnv}.js`);
7+
if (existsSync(path)) {
8+
console.log(`Loading ENV specific webpack configuration file ${path}`);
9+
return require(path);
10+
} else {
11+
return webpackConfig;
12+
}
13+
};
14+
15+
module.exports = envSpecificConfig();

test/dummy_shakapacker/config/webpacker.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ default: &default
1313
# Reload manifest.json on all requests so we reload latest compiled packs
1414
cache_manifest: false
1515

16-
extensions:
17-
- .coffee
18-
- .erb
19-
- .js
20-
- .jsx
21-
- .ts
22-
- .vue
23-
- .sass
24-
- .scss
25-
- .css
26-
- .png
27-
- .svg
28-
- .gif
29-
- .jpeg
30-
- .jpg
31-
3216
development:
3317
<<: *default
3418
compile: true

test/dummy_shakapacker/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"babel-loader": "^8.2.5",
1010
"babel-plugin-macros": "^3.1.0",
1111
"compression-webpack-plugin": "^9.2.0",
12+
"create-react-class": "^15.6.2",
1213
"css-loader": "^5.2.7",
1314
"css-minimizer-webpack-plugin": "^2.0.0",
1415
"mini-css-extract-plugin": "^1.6.2",
1516
"pnp-webpack-plugin": "^1.7.0",
1617
"react": "^17.0.2",
1718
"react-dom": "^17.0.2",
19+
"react_ujs": "file:.yalc/react_ujs",
1820
"shakapacker": "^6.4.1",
1921
"style-loader": "^3.3.1",
2022
"terser-webpack-plugin": "^5.3.3",
@@ -25,8 +27,12 @@
2527
"webpack-sources": "^3.2.3"
2628
},
2729
"devDependencies": {
30+
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
2831
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
2932
"react-refresh": "^0.13.0",
3033
"webpack-dev-server": "^4.9.2"
34+
},
35+
"scripts": {
36+
"yalc-postinstall": "yalc link react_ujs"
3137
}
3238
}

0 commit comments

Comments
 (0)