Skip to content

Commit d4d43a4

Browse files
authored
Test resources_pod() (#30)
1 parent 5e5af19 commit d4d43a4

File tree

8 files changed

+87
-1
lines changed

8 files changed

+87
-1
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v2
13+
- name: minitest
14+
run: |
15+
ruby -Ilib:test test/test_test_app.rb
1316
- name: Install
1417
run: |
1518
yarn

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
.clang-format
44
.gitattributes
55
.github/
6+
.rubocop.yml
67
.swiftlint.yml
8+
Gemfile
79
example/
10+
scripts/
11+
test/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "TestFixture",
3+
"displayName": "TestFixture",
4+
"components": {
5+
"TestFixture": {
6+
"displayName": "Test"
7+
}
8+
},
9+
"resources": [
10+
"dist/assets",
11+
"dist/main.jsbundle"
12+
]
13+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "TestFixture",
3+
"displayName": "TestFixture",
4+
"components": {
5+
"TestFixture": {
6+
"displayName": "Test"
7+
}
8+
}
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

test/test_test_app.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
#
7+
8+
require('minitest/autorun')
9+
10+
require_relative('../test_app')
11+
12+
def app_manifest_path(project_root, podspec_path)
13+
File.join(project_root, podspec_path, 'ReactTestApp-Resources.podspec.json')
14+
end
15+
16+
class TestTestApp < Minitest::Test
17+
def test_resources_pod_returns_spec_path
18+
assert_nil(resources_pod('/'))
19+
assert_nil(resources_pod('.'))
20+
21+
project_root = File.join(__dir__, 'fixtures', 'without_resources')
22+
assert_nil(resources_pod(project_root))
23+
24+
project_root = File.join(__dir__, 'fixtures', 'without_resources', 'ios')
25+
assert_nil(resources_pod(project_root))
26+
27+
project_root = File.join(__dir__, 'fixtures', 'with_resources')
28+
assert_equal('.', resources_pod(project_root))
29+
30+
project_root = File.join(__dir__, 'fixtures', 'with_resources', 'ios')
31+
assert_equal('..', resources_pod(project_root))
32+
end
33+
34+
def test_resources_pod_writes_podspec
35+
[
36+
File.join(__dir__, 'fixtures', 'with_resources'),
37+
File.join(__dir__, 'fixtures', 'with_resources', 'ios')
38+
].each do |project_root|
39+
begin
40+
podspec_path = resources_pod(project_root)
41+
manifest_path = app_manifest_path(project_root, podspec_path)
42+
manifest = JSON.parse(File.read(manifest_path))
43+
44+
assert_equal(%w[dist/assets dist/main.jsbundle], manifest['resources'].sort)
45+
ensure
46+
File.delete(manifest_path)
47+
end
48+
end
49+
end
50+
end

test_app.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# LICENSE file in the root directory of this source tree.
66
#
77

8+
require('json')
9+
require('pathname')
10+
811
def autolink_script_path
912
package_path = resolve_module('@react-native-community/cli-platform-ios')
1013
File.join(package_path, 'native_modules')
@@ -37,7 +40,7 @@ def resources_pod(project_root, current_dir = project_root)
3740

3841
podspec_path = File.join(current_dir, 'ReactTestApp-Resources.podspec.json')
3942
File.write(podspec_path, spec.to_json)
40-
at_exit { File.delete(podspec_path) }
43+
at_exit { File.delete(podspec_path) if File.exist?(podspec_path) }
4144
Pathname.new(current_dir).relative_path_from(project_root).to_s
4245
end
4346

0 commit comments

Comments
 (0)