integration-tests-rails 1.0.2 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12ec9fa8a5503ba21d04c3700fee04a00413b072a1adb9918fb75714c3e92c8d
4
- data.tar.gz: 50c08830a21433430b183ae184df578656108d8ca2257317034f686638d6e619
3
+ metadata.gz: be57f4d8d66105663b9c082866bcade277fceec8e89254bfd5fa88d3c6c6ec0d
4
+ data.tar.gz: 0c45dd9db327c01f8e93a6c92c327d45153cdc8ca8ba6a172190d809661490e3
5
5
  SHA512:
6
- metadata.gz: 9ac0c50347e0bfd28fae19f6495fa61ce1977a863929ed99885ed7c1c0b34c1627a3a5fc82dc9a010ba6c6fcf1cb11340191a7e57a1c31862401581759873ad7
7
- data.tar.gz: 3ac047eb7ff7c4da5698b9ea90eb9b0f4e5dedf8f0b5992423a87a582a830b70f339cf3d0309232cf3d0a554a8e2a1fce979e97d8910cf9d07263a75d2879691
6
+ metadata.gz: 2aa3bbefef1c3ec24a53c9f6e1cd4c3ac2b0549f408b79aa1de3689503e39b96a7fca47a4ffcf61b6ebf9ff9e0f7d4bbf2fa417d5cb36b4b363e896bb9a1fcd0
7
+ data.tar.gz: a46a8871be677914d9faa52703006719a9ca097e8b5bac8503234ffb5752e6ef097c5d3267dd5df7facd30f0fd6479a8d8f8d023db4046b77b2d1400e5be3876
data/README.md CHANGED
@@ -176,6 +176,18 @@ let(:script) do
176
176
  end
177
177
  ```
178
178
 
179
+ There is a `function` component that is the same as the `script` component but `function` automatically wraps the containing JavaScript code in an arrow function and executes it. The above can be rewritten as:
180
+
181
+ ```ruby
182
+ let(:function) do
183
+ <<~JS
184
+ const value1 = CustomCode.getValue1();
185
+ const value2 = CustomCode.getValue2();
186
+ return CustomCode.combineValues(value1, value2);
187
+ JS
188
+ end
189
+ ```
190
+
179
191
  The above will successfully execute the three statements and return the value in `result`. However, this can become a problem if the JavaScript code being tested relies on waiting for each statement to complete. In such cases, it is recommended to use an array instead in `script`:
180
192
 
181
193
  ```ruby
@@ -191,8 +203,9 @@ let(:script) do
191
203
  end
192
204
  ```
193
205
 
194
- In such cases where `script` is an array, the `result` component will contain the return value of the **last statement only**.
206
+ In such cases where `script` is an array, the `result` component will contain the return value of the **last statement only**. `function` also supports arrays; each element will be wrapped in an arrow function and executed sequentially.
195
207
 
208
+ **Do not use `script` and `function` components as the same time in an example.**
196
209
 
197
210
  ## Integration Testing
198
211
 
@@ -15,7 +15,26 @@ module IntegrationTestsRails
15
15
  end
16
16
  end
17
17
 
18
- let(:script) { nil }
18
+ let(:script) do
19
+ case function
20
+ when Array
21
+ function.map! do |fn|
22
+ <<~JSCODE
23
+ (() => {
24
+ #{fn}
25
+ })();
26
+ JSCODE
27
+ end
28
+ when String
29
+ <<~JSCODE
30
+ (() => {
31
+ #{function}
32
+ })();
33
+ JSCODE
34
+ end
35
+ end
36
+
37
+ let(:function) { nil }
19
38
 
20
39
  before do
21
40
  visit tests_path
@@ -126,11 +126,13 @@ module IntegrationTestsRails
126
126
  }
127
127
 
128
128
  const instrumentedDir = '#{config.output_path}';
129
+ const backupDir = '#{config.backup_path}';
130
+ const sourceDir = '#{config.source_path}';
129
131
  const instrumentedFiles = findJsFiles(instrumentedDir);
130
132
 
131
133
  instrumentedFiles.forEach(instrumentedFile => {
132
134
  const relativePath = path.relative(instrumentedDir, instrumentedFile);
133
- const originalFile = path.join('#{config.source_path}', relativePath);
135
+ const originalFile = path.join(sourceDir, relativePath);
134
136
 
135
137
  if (coverageMap.data[originalFile]) return;
136
138
 
@@ -140,6 +142,7 @@ module IntegrationTestsRails
140
142
 
141
143
  if (match && match[1]) {
142
144
  const coverageData = eval('(' + match[1] + ')');
145
+ // Keep original path for display
143
146
  coverageData.path = originalFile;
144
147
  coverageMap.addFileCoverage(coverageData);
145
148
  }
@@ -150,7 +153,21 @@ module IntegrationTestsRails
150
153
 
151
154
  const context = libReport.createContext({
152
155
  dir: 'coverage/javascript',
153
- coverageMap: coverageMap
156
+ coverageMap: coverageMap,
157
+ sourceFinder: function(filePath) {
158
+ const relativePath = path.relative(sourceDir, filePath);
159
+ const backupFile = path.join(backupDir, relativePath);
160
+
161
+ try {
162
+ // Read content from backup (original source)
163
+ if (fs.existsSync(backupFile)) {
164
+ return fs.readFileSync(backupFile, 'utf8');
165
+ }
166
+ } catch(e) {
167
+ console.error('Could not read backup file:', backupFile, e.message);
168
+ }
169
+ return null;
170
+ }
154
171
  });
155
172
 
156
173
  ['html', 'lcov', 'cobertura'].forEach(reportType => {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IntegrationTestsRails
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integration-tests-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien