ruby_wasm_ui 0.8.3 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +0 -2
- data/Makefile +56 -0
- data/README.md +26 -6
- data/examples/.gitignore +4 -0
- data/examples/Gemfile.lock +15 -17
- data/examples/src/index.html +21 -0
- data/examples/src/index.rb +26 -0
- data/exe/ruby-wasm-ui +6 -0
- data/lib/ruby_wasm_ui/cli/command/base.rb +192 -0
- data/lib/ruby_wasm_ui/cli/command/dev.rb +207 -0
- data/lib/ruby_wasm_ui/cli/command/pack.rb +36 -0
- data/lib/ruby_wasm_ui/cli/command/rebuild.rb +38 -0
- data/lib/ruby_wasm_ui/cli/command/setup.rb +159 -0
- data/lib/ruby_wasm_ui/cli/command.rb +48 -0
- data/lib/ruby_wasm_ui/version.rb +1 -1
- data/lib/ruby_wasm_ui.rb +8 -8
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/packages/npm-packages/runtime/package-lock.json +2 -2
- data/packages/npm-packages/runtime/package.json +1 -1
- data/packages/npm-packages/runtime/rollup.config.mjs +1 -1
- data/spec/ruby_wasm_ui/cli/command/base_spec.rb +503 -0
- data/spec/ruby_wasm_ui/cli/command/dev_spec.rb +442 -0
- data/spec/ruby_wasm_ui/cli/command/pack_spec.rb +131 -0
- data/spec/ruby_wasm_ui/cli/command/rebuild_spec.rb +95 -0
- data/spec/ruby_wasm_ui/cli/command/setup_spec.rb +251 -0
- data/spec/ruby_wasm_ui/cli/command_spec.rb +118 -0
- data/{packages/npm-packages/runtime/spec → spec}/spec_helper.rb +1 -1
- metadata +96 -38
- data/packages/npm-packages/runtime/Gemfile +0 -3
- data/packages/npm-packages/runtime/Gemfile.lock +0 -26
- /data/lib/ruby_wasm_ui/{app.rb → runtime/app.rb} +0 -0
- /data/lib/ruby_wasm_ui/{component.rb → runtime/component.rb} +0 -0
- /data/lib/ruby_wasm_ui/{dispatcher.rb → runtime/dispatcher.rb} +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/attributes.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/destroy_dom.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/events.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/mount_dom.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/patch_dom.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom → runtime/dom}/scheduler.rb +0 -0
- /data/lib/ruby_wasm_ui/{dom.rb → runtime/dom.rb} +0 -0
- /data/lib/ruby_wasm_ui/{nodes_equal.rb → runtime/nodes_equal.rb} +0 -0
- /data/lib/ruby_wasm_ui/{template → runtime/template}/build_conditional_group.rb +0 -0
- /data/lib/ruby_wasm_ui/{template → runtime/template}/build_for_group.rb +0 -0
- /data/lib/ruby_wasm_ui/{template → runtime/template}/build_vdom.rb +0 -0
- /data/lib/ruby_wasm_ui/{template → runtime/template}/parser.rb +0 -0
- /data/lib/ruby_wasm_ui/{template.rb → runtime/template.rb} +0 -0
- /data/lib/ruby_wasm_ui/{utils → runtime/utils}/arrays.rb +0 -0
- /data/lib/ruby_wasm_ui/{utils → runtime/utils}/objects.rb +0 -0
- /data/lib/ruby_wasm_ui/{utils → runtime/utils}/props.rb +0 -0
- /data/lib/ruby_wasm_ui/{utils → runtime/utils}/strings.rb +0 -0
- /data/lib/ruby_wasm_ui/{utils.rb → runtime/utils.rb} +0 -0
- /data/lib/ruby_wasm_ui/{vdom.rb → runtime/vdom.rb} +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/component_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/dom/scheduler_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/nodes_equal_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/template/build_conditional_group_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/template/build_for_group_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/template/build_vdom_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/template/parser_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/utils/arrays_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/utils/objects_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/utils/props_spec.rb +0 -0
- /data/{packages/npm-packages/runtime/spec/ruby_wasm_ui → spec/ruby_wasm_ui/runtime}/utils/strings_spec.rb +0 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'tmpdir'
|
|
6
|
+
|
|
7
|
+
RSpec.describe RubyWasmUi::Cli::Command::Base do
|
|
8
|
+
let(:base_instance) { described_class.new }
|
|
9
|
+
|
|
10
|
+
describe '#run' do
|
|
11
|
+
it 'raises NotImplementedError' do
|
|
12
|
+
expect { base_instance.run([]) }.to raise_error(NotImplementedError, /Subclasses must implement #run/)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#run_command' do
|
|
17
|
+
context 'when command succeeds' do
|
|
18
|
+
it 'executes the command and outputs stdout' do
|
|
19
|
+
expect { base_instance.send(:run_command, 'echo "test output"') }.to output(
|
|
20
|
+
/test output/
|
|
21
|
+
).to_stdout
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'does not raise error' do
|
|
25
|
+
expect { base_instance.send(:run_command, 'echo "test"') }.not_to raise_error
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'returns true' do
|
|
29
|
+
result = base_instance.send(:run_command, 'echo "test"')
|
|
30
|
+
expect(result).to be true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when command fails' do
|
|
35
|
+
it 'outputs error message and exits by default' do
|
|
36
|
+
expect { base_instance.send(:run_command, 'false') }.to output(
|
|
37
|
+
/Command failed: false/
|
|
38
|
+
).to_stdout.and raise_error(SystemExit)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'exits with correct status code' do
|
|
42
|
+
expect { base_instance.send(:run_command, 'false') }.to raise_error(SystemExit) do |error|
|
|
43
|
+
expect(error.status).to eq(1)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'when exit_on_error is false' do
|
|
48
|
+
it 'outputs error message but does not exit' do
|
|
49
|
+
expect { base_instance.send(:run_command, 'false', exit_on_error: false) }.to output(
|
|
50
|
+
/Command failed: false/
|
|
51
|
+
).to_stdout
|
|
52
|
+
expect { base_instance.send(:run_command, 'false', exit_on_error: false) }.not_to raise_error
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'returns false' do
|
|
56
|
+
result = base_instance.send(:run_command, 'false', exit_on_error: false)
|
|
57
|
+
expect(result).to be false
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe '#ensure_src_directory' do
|
|
64
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
65
|
+
let(:original_dir) { Dir.pwd }
|
|
66
|
+
|
|
67
|
+
around do |example|
|
|
68
|
+
Dir.chdir(temp_dir) do
|
|
69
|
+
example.run
|
|
70
|
+
end
|
|
71
|
+
ensure
|
|
72
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context 'when src directory does not exist' do
|
|
76
|
+
it 'outputs error message and exits' do
|
|
77
|
+
expect { base_instance.send(:ensure_src_directory) }.to output(
|
|
78
|
+
/src directory not found. Please run 'ruby-wasm-ui setup' first./
|
|
79
|
+
).to_stdout.and raise_error(SystemExit)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'exits with status 1' do
|
|
83
|
+
expect { base_instance.send(:ensure_src_directory) }.to raise_error(SystemExit) do |error|
|
|
84
|
+
expect(error.status).to eq(1)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'when src directory exists' do
|
|
90
|
+
before do
|
|
91
|
+
FileUtils.mkdir_p('src')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'does not raise error' do
|
|
95
|
+
expect { base_instance.send(:ensure_src_directory) }.not_to raise_error
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'does not output error message' do
|
|
99
|
+
expect { base_instance.send(:ensure_src_directory) }.not_to output(
|
|
100
|
+
/src directory not found/
|
|
101
|
+
).to_stdout
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#ensure_ruby_wasm' do
|
|
107
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
108
|
+
let(:original_dir) { Dir.pwd }
|
|
109
|
+
|
|
110
|
+
around do |example|
|
|
111
|
+
Dir.chdir(temp_dir) do
|
|
112
|
+
example.run
|
|
113
|
+
end
|
|
114
|
+
ensure
|
|
115
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context 'when ruby.wasm does not exist' do
|
|
119
|
+
it 'outputs error message and exits' do
|
|
120
|
+
expect { base_instance.send(:ensure_ruby_wasm) }.to output(
|
|
121
|
+
/ruby.wasm not found. Please run 'ruby-wasm-ui setup' first./
|
|
122
|
+
).to_stdout.and raise_error(SystemExit)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it 'exits with status 1' do
|
|
126
|
+
expect { base_instance.send(:ensure_ruby_wasm) }.to raise_error(SystemExit) do |error|
|
|
127
|
+
expect(error.status).to eq(1)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'when ruby.wasm exists' do
|
|
133
|
+
before do
|
|
134
|
+
FileUtils.touch('ruby.wasm')
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'does not raise error' do
|
|
138
|
+
expect { base_instance.send(:ensure_ruby_wasm) }.not_to raise_error
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'does not output error message' do
|
|
142
|
+
expect { base_instance.send(:ensure_ruby_wasm) }.not_to output(
|
|
143
|
+
/ruby.wasm not found/
|
|
144
|
+
).to_stdout
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#check_ruby_version' do
|
|
150
|
+
context 'when Ruby version is 3.2 or higher' do
|
|
151
|
+
before do
|
|
152
|
+
stub_const('RUBY_VERSION', '3.2.0')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'returns the version string' do
|
|
156
|
+
result = base_instance.send(:check_ruby_version)
|
|
157
|
+
expect(result).to eq('3.2')
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it 'does not exit' do
|
|
161
|
+
expect { base_instance.send(:check_ruby_version) }.not_to raise_error
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context 'when Ruby version is 3.4' do
|
|
166
|
+
before do
|
|
167
|
+
stub_const('RUBY_VERSION', '3.4.0')
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'returns the version string' do
|
|
171
|
+
result = base_instance.send(:check_ruby_version)
|
|
172
|
+
expect(result).to eq('3.4')
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context 'when Ruby version is less than 3.2' do
|
|
177
|
+
context 'when Ruby version is 3.1' do
|
|
178
|
+
before do
|
|
179
|
+
stub_const('RUBY_VERSION', '3.1.5')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it 'outputs error message and exits' do
|
|
183
|
+
expect { base_instance.send(:check_ruby_version) }.to output(
|
|
184
|
+
/\[ERROR\] Ruby WASM requires Ruby 3.2 or higher. Current version: 3.1.5/
|
|
185
|
+
).to_stdout.and raise_error(SystemExit) do |error|
|
|
186
|
+
expect(error.status).to eq(1)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
context 'when Ruby version is 2.7' do
|
|
192
|
+
before do
|
|
193
|
+
stub_const('RUBY_VERSION', '2.7.8')
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'outputs error message and exits' do
|
|
197
|
+
expect { base_instance.send(:check_ruby_version) }.to output(
|
|
198
|
+
/\[ERROR\] Ruby WASM requires Ruby 3.2 or higher. Current version: 2.7.8/
|
|
199
|
+
).to_stdout.and raise_error(SystemExit) do |error|
|
|
200
|
+
expect(error.status).to eq(1)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe '#configure_excluded_gems' do
|
|
208
|
+
before do
|
|
209
|
+
# Clear EXCLUDED_GEMS before each test
|
|
210
|
+
RubyWasm::Packager::EXCLUDED_GEMS.clear if defined?(RubyWasm::Packager::EXCLUDED_GEMS)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it 'excludes rack, puma, nio4r, listen, and ffi gems' do
|
|
214
|
+
allow(Bundler).to receive(:definition).and_return(
|
|
215
|
+
double(
|
|
216
|
+
resolve: double(
|
|
217
|
+
materialize: [
|
|
218
|
+
double(name: 'rack'),
|
|
219
|
+
double(name: 'puma'),
|
|
220
|
+
double(name: 'nio4r'),
|
|
221
|
+
double(name: 'listen'),
|
|
222
|
+
double(name: 'ffi'),
|
|
223
|
+
double(name: 'js'),
|
|
224
|
+
double(name: 'ruby_wasm')
|
|
225
|
+
]
|
|
226
|
+
),
|
|
227
|
+
requested_dependencies: []
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
base_instance.send(:configure_excluded_gems)
|
|
232
|
+
|
|
233
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).to include('rack', 'puma', 'nio4r', 'listen', 'ffi')
|
|
234
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).not_to include('js', 'ruby_wasm')
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'always excludes nio4r, puma, rack, listen, and ffi even if not in dependencies' do
|
|
238
|
+
allow(Bundler).to receive(:definition).and_return(
|
|
239
|
+
double(
|
|
240
|
+
resolve: double(
|
|
241
|
+
materialize: [
|
|
242
|
+
double(name: 'js'),
|
|
243
|
+
double(name: 'ruby_wasm')
|
|
244
|
+
]
|
|
245
|
+
),
|
|
246
|
+
requested_dependencies: []
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
base_instance.send(:configure_excluded_gems)
|
|
251
|
+
|
|
252
|
+
# Always excluded gems should be in the list even if not in dependencies
|
|
253
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).to include('nio4r', 'puma', 'rack', 'listen', 'ffi')
|
|
254
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).not_to include('js', 'ruby_wasm')
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it 'excludes development/test gems' do
|
|
258
|
+
allow(Bundler).to receive(:definition).and_return(
|
|
259
|
+
double(
|
|
260
|
+
resolve: double(
|
|
261
|
+
materialize: [
|
|
262
|
+
double(name: 'rspec'),
|
|
263
|
+
double(name: 'rubocop'),
|
|
264
|
+
double(name: 'rake'),
|
|
265
|
+
double(name: 'js')
|
|
266
|
+
]
|
|
267
|
+
),
|
|
268
|
+
requested_dependencies: []
|
|
269
|
+
)
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
base_instance.send(:configure_excluded_gems)
|
|
273
|
+
|
|
274
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).to include('rspec', 'rubocop', 'rake')
|
|
275
|
+
expect(RubyWasm::Packager::EXCLUDED_GEMS).not_to include('js')
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe '#build_ruby_wasm' do
|
|
280
|
+
let(:cli_instance) { instance_double(RubyWasm::CLI) }
|
|
281
|
+
|
|
282
|
+
before do
|
|
283
|
+
allow(RubyWasm::CLI).to receive(:new).and_return(cli_instance)
|
|
284
|
+
allow(cli_instance).to receive(:run)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it 'executes rbwasm build command with correct arguments' do
|
|
288
|
+
expect(RubyWasm::CLI).to receive(:new).with(stdout: $stdout, stderr: $stderr).and_return(cli_instance)
|
|
289
|
+
expect(cli_instance).to receive(:run).with(['build', '--ruby-version', '3.2', '-o', 'ruby.wasm'])
|
|
290
|
+
|
|
291
|
+
base_instance.send(:build_ruby_wasm, '3.2')
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it 'executes rbwasm build command with different version' do
|
|
295
|
+
expect(RubyWasm::CLI).to receive(:new).with(stdout: $stdout, stderr: $stderr).and_return(cli_instance)
|
|
296
|
+
expect(cli_instance).to receive(:run).with(['build', '--ruby-version', '3.4', '-o', 'ruby.wasm'])
|
|
297
|
+
|
|
298
|
+
base_instance.send(:build_ruby_wasm, '3.4')
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
describe '#ensure_dist_directory' do
|
|
303
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
304
|
+
let(:original_dir) { Dir.pwd }
|
|
305
|
+
|
|
306
|
+
around do |example|
|
|
307
|
+
Dir.chdir(temp_dir) do
|
|
308
|
+
example.run
|
|
309
|
+
end
|
|
310
|
+
ensure
|
|
311
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
context 'when dist directory does not exist' do
|
|
315
|
+
it 'creates dist directory' do
|
|
316
|
+
expect(Dir.exist?('dist')).to be false
|
|
317
|
+
base_instance.send(:ensure_dist_directory)
|
|
318
|
+
expect(Dir.exist?('dist')).to be true
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it 'outputs creation message' do
|
|
322
|
+
expect { base_instance.send(:ensure_dist_directory) }.to output(
|
|
323
|
+
/Created dist directory/
|
|
324
|
+
).to_stdout
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
context 'when dist directory already exists' do
|
|
329
|
+
before do
|
|
330
|
+
FileUtils.mkdir_p('dist')
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it 'does not create dist directory again' do
|
|
334
|
+
expect(Dir).not_to receive(:mkdir)
|
|
335
|
+
base_instance.send(:ensure_dist_directory)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it 'does not output creation message' do
|
|
339
|
+
expect { base_instance.send(:ensure_dist_directory) }.not_to output(
|
|
340
|
+
/Created dist directory/
|
|
341
|
+
).to_stdout
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
describe '#copy_non_ruby_files' do
|
|
347
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
348
|
+
let(:original_dir) { Dir.pwd }
|
|
349
|
+
|
|
350
|
+
around do |example|
|
|
351
|
+
Dir.chdir(temp_dir) do
|
|
352
|
+
example.run
|
|
353
|
+
end
|
|
354
|
+
ensure
|
|
355
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
context 'when non-Ruby files exist' do
|
|
359
|
+
before do
|
|
360
|
+
FileUtils.mkdir_p('src')
|
|
361
|
+
File.write('src/index.html', '<html></html>')
|
|
362
|
+
File.write('src/style.css', 'body {}')
|
|
363
|
+
File.write('src/app.rb', 'puts "hello"')
|
|
364
|
+
FileUtils.mkdir_p('src/subdir')
|
|
365
|
+
File.write('src/subdir/script.js', 'console.log("test")')
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
it 'copies HTML files to dist' do
|
|
369
|
+
base_instance.send(:copy_non_ruby_files)
|
|
370
|
+
expect(File.exist?('dist/index.html')).to be true
|
|
371
|
+
expect(File.read('dist/index.html')).to eq('<html></html>')
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it 'copies CSS files to dist' do
|
|
375
|
+
base_instance.send(:copy_non_ruby_files)
|
|
376
|
+
expect(File.exist?('dist/style.css')).to be true
|
|
377
|
+
expect(File.read('dist/style.css')).to eq('body {}')
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it 'does not copy Ruby files' do
|
|
381
|
+
base_instance.send(:copy_non_ruby_files)
|
|
382
|
+
expect(File.exist?('dist/app.rb')).to be false
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it 'preserves directory structure' do
|
|
386
|
+
base_instance.send(:copy_non_ruby_files)
|
|
387
|
+
expect(File.exist?('dist/subdir/script.js')).to be true
|
|
388
|
+
expect(File.read('dist/subdir/script.js')).to eq('console.log("test")')
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
it 'outputs success message with copied files' do
|
|
392
|
+
expect { base_instance.send(:copy_non_ruby_files) }.to output(
|
|
393
|
+
/Copied.*file\(s\)/
|
|
394
|
+
).to_stdout
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
context 'when no non-Ruby files exist' do
|
|
399
|
+
before do
|
|
400
|
+
FileUtils.mkdir_p('src')
|
|
401
|
+
File.write('src/app.rb', 'puts "hello"')
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it 'outputs no files message' do
|
|
405
|
+
expect { base_instance.send(:copy_non_ruby_files) }.to output(
|
|
406
|
+
/No non-Ruby files to copy/
|
|
407
|
+
).to_stdout
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
describe '#pack_wasm' do
|
|
413
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
414
|
+
let(:original_dir) { Dir.pwd }
|
|
415
|
+
|
|
416
|
+
around do |example|
|
|
417
|
+
Dir.chdir(temp_dir) do
|
|
418
|
+
example.run
|
|
419
|
+
end
|
|
420
|
+
ensure
|
|
421
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
before do
|
|
425
|
+
FileUtils.mkdir_p('src')
|
|
426
|
+
FileUtils.touch('ruby.wasm')
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
context 'when command succeeds' do
|
|
430
|
+
before do
|
|
431
|
+
allow(base_instance).to receive(:run_command).and_return(true)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it 'executes rbwasm pack command via run_command' do
|
|
435
|
+
expect(base_instance).to receive(:run_command).with(
|
|
436
|
+
'bundle exec rbwasm pack ruby.wasm --dir ./src::./src -o dist/src.wasm',
|
|
437
|
+
exit_on_error: true
|
|
438
|
+
)
|
|
439
|
+
base_instance.send(:pack_wasm)
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
it 'outputs pack message with default prefix' do
|
|
443
|
+
expect { base_instance.send(:pack_wasm) }.to output(
|
|
444
|
+
/Packing: bundle exec rbwasm pack/
|
|
445
|
+
).to_stdout
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
it 'outputs pack message with custom prefix' do
|
|
449
|
+
expect { base_instance.send(:pack_wasm, log_prefix: 'Building') }.to output(
|
|
450
|
+
/Building: bundle exec rbwasm pack/
|
|
451
|
+
).to_stdout
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
it 'outputs success message' do
|
|
455
|
+
expect { base_instance.send(:pack_wasm) }.to output(
|
|
456
|
+
/Pack completed/
|
|
457
|
+
).to_stdout
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
it 'returns true' do
|
|
461
|
+
result = base_instance.send(:pack_wasm)
|
|
462
|
+
expect(result).to be true
|
|
463
|
+
end
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
context 'when command fails' do
|
|
467
|
+
before do
|
|
468
|
+
allow(base_instance).to receive(:run_command).and_raise(SystemExit.new(1))
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
it 'outputs error message and exits by default' do
|
|
472
|
+
expect { base_instance.send(:pack_wasm) }.to raise_error(SystemExit)
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it 'exits with status 1' do
|
|
476
|
+
expect { base_instance.send(:pack_wasm) }.to raise_error(SystemExit) do |error|
|
|
477
|
+
expect(error.status).to eq(1)
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
context 'when exit_on_error is false' do
|
|
482
|
+
before do
|
|
483
|
+
allow(base_instance).to receive(:run_command).and_return(false)
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
it 'does not raise error' do
|
|
487
|
+
expect { base_instance.send(:pack_wasm, exit_on_error: false) }.not_to raise_error
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
it 'returns false' do
|
|
491
|
+
result = base_instance.send(:pack_wasm, exit_on_error: false)
|
|
492
|
+
expect(result).to be false
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it 'does not output success message when command fails' do
|
|
496
|
+
expect { base_instance.send(:pack_wasm, exit_on_error: false) }.not_to output(
|
|
497
|
+
/Pack completed/
|
|
498
|
+
).to_stdout
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
end
|