js-routes 2.0.7 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+
2
+ require "active_support/core_ext/string/strip"
3
+ require "fileutils"
4
+ require "open3"
5
+ require "spec_helper"
6
+
7
+ describe JsRoutes, "compatibility with DTS" do
8
+
9
+ OPTIONS = {module_type: 'DTS', include: [/^inboxes$/, /^inbox_message_attachment$/]}
10
+ let(:extra_options) do
11
+ {}
12
+ end
13
+
14
+ let(:generated_js) do
15
+ JsRoutes.generate({**OPTIONS, **extra_options})
16
+ end
17
+
18
+ context "when file is generated" do
19
+ let(:dir_name) do
20
+ File.expand_path(__dir__ + "/dts")
21
+ end
22
+
23
+ let(:file_name) do
24
+ dir_name + "/routes.spec.d.ts"
25
+ end
26
+
27
+ before do
28
+ FileUtils.mkdir_p(dir_name)
29
+ File.write(file_name, generated_js)
30
+ end
31
+
32
+ it "has no compile errors", :slow do
33
+ command = "yarn tsc --strict --noEmit -p spec/tsconfig.json"
34
+ stdout, stderr, status = Open3.capture3(command)
35
+ expect(stderr).to eq("")
36
+ expect(stdout).to include("Done in ")
37
+ expect(status).to eq(0)
38
+ end
39
+ end
40
+
41
+ context "when camel case is enabled" do
42
+ let(:extra_options) { {camel_case: true} }
43
+
44
+ it "camelizes route name and arguments" do
45
+
46
+ expect(generated_js).to include(<<-DOC.rstrip)
47
+ /**
48
+ * Generates rails route to
49
+ * /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
50
+ * @param {any} inboxId
51
+ * @param {any} messageId
52
+ * @param {any} id
53
+ * @param {object | undefined} options
54
+ * @returns {string} route path
55
+ */
56
+ export const inboxMessageAttachmentPath: ((
57
+ inboxId: RequiredRouteParameter,
58
+ messageId: RequiredRouteParameter,
59
+ id: RequiredRouteParameter,
60
+ options?: {format?: OptionalRouteParameter} & RouteOptions
61
+ ) => string) & RouteHelperExtras;
62
+ DOC
63
+ end
64
+ end
65
+
66
+ it "exports route helpers" do
67
+ expect(generated_js).to include(<<-DOC.rstrip)
68
+ /**
69
+ * Generates rails route to
70
+ * /inboxes(.:format)
71
+ * @param {object | undefined} options
72
+ * @returns {string} route path
73
+ */
74
+ export const inboxes_path: ((
75
+ options?: {format?: OptionalRouteParameter} & RouteOptions
76
+ ) => string) & RouteHelperExtras;
77
+ DOC
78
+ expect(generated_js).to include(<<-DOC.rstrip)
79
+ /**
80
+ * Generates rails route to
81
+ * /inboxes/:inbox_id/messages/:message_id/attachments/:id(.:format)
82
+ * @param {any} inbox_id
83
+ * @param {any} message_id
84
+ * @param {any} id
85
+ * @param {object | undefined} options
86
+ * @returns {string} route path
87
+ */
88
+ export const inbox_message_attachment_path: ((
89
+ inbox_id: RequiredRouteParameter,
90
+ message_id: RequiredRouteParameter,
91
+ id: RequiredRouteParameter,
92
+ options?: {format?: OptionalRouteParameter} & RouteOptions
93
+ ) => string) & RouteHelperExtras
94
+ DOC
95
+ end
96
+
97
+ it "exports utility methods" do
98
+ expect(generated_js).to include("export const serialize: RouterExposedMethods['serialize'];")
99
+ end
100
+
101
+ it "prevents all types from automatic export" do
102
+ expect(generated_js).to include("export {};")
103
+ end
104
+
105
+ describe "compiled javascript asset" do
106
+ subject { ERB.new(File.read("app/assets/javascripts/js-routes.js.erb")).result(binding) }
107
+ it "should have js routes code" do
108
+ is_expected.to include("export const inbox_message_path = __jsr.r(")
109
+ end
110
+ end
111
+ end
@@ -5,7 +5,7 @@
5
5
  require 'spec_helper'
6
6
  require "fileutils"
7
7
 
8
- describe "after Rails initialization" do
8
+ describe "after Rails initialization", :slow do
9
9
  NAME = Rails.root.join('app', 'assets', 'javascripts', 'routes.js').to_s
10
10
 
11
11
  def sprockets_v3?
@@ -122,7 +122,7 @@ describe "after Rails initialization" do
122
122
  end
123
123
  end
124
124
 
125
- describe "JSRoutes thread safety" do
125
+ describe "JSRoutes thread safety", :slow do
126
126
  before do
127
127
  begin
128
128
  Rails.application.initialize!
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "include": ["./**/*.spec.ts"]
4
+ }
data/tsconfig.json CHANGED
@@ -3,14 +3,10 @@
3
3
  "target": "es2019",
4
4
  "lib": ["es2020", "dom"],
5
5
  "module": "commonjs",
6
- "outDir": "lib",
7
6
  "sourceMap": false,
8
7
  "declaration": true,
9
8
  "allowSyntheticDefaultImports": true,
10
- "resolveJsonModule": true,
11
- "typeRoots": ["node_modules/@types", "./@types"],
12
-
13
- "strict": true,
9
+ "resolveJsonModule": false,
14
10
  "strictNullChecks": true,
15
11
  "noImplicitAny": true,
16
12
  "noImplicitThis": true,
@@ -22,11 +18,11 @@
22
18
  "forceConsistentCasingInFileNames": true,
23
19
  "emitDecoratorMetadata": true,
24
20
  "experimentalDecorators": true
21
+
25
22
  },
26
23
  "ts-node": {
27
24
  "files": true,
28
25
  "transpileOnly": false
29
26
  },
30
- "include": ["./**/*.ts", "lib/**/*.json", "./**/*.tsx"],
31
- "exclude": ["node_modules", "**/thorn", "**/support", "**/tmp"]
27
+ "include": ["lib/*.ts"]
32
28
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: 3.10.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: 3.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -171,11 +171,15 @@ files:
171
171
  - lib/js-routes.rb
172
172
  - lib/js_routes.rb
173
173
  - lib/js_routes/engine.rb
174
+ - lib/js_routes/generators/webpacker.rb
174
175
  - lib/js_routes/version.rb
175
176
  - lib/routes.d.ts
176
177
  - lib/routes.js
177
178
  - lib/routes.ts
178
179
  - lib/tasks/js_routes.rake
180
+ - lib/templates/erb.js
181
+ - lib/templates/initializer.rb
182
+ - lib/templates/routes.js.erb
179
183
  - package.json
180
184
  - spec/dummy/app/assets/config/manifest.js
181
185
  - spec/dummy/app/assets/javascripts/.gitkeep
@@ -183,6 +187,9 @@ files:
183
187
  - spec/js_routes/default_serializer_spec.rb
184
188
  - spec/js_routes/module_types/amd_spec.rb
185
189
  - spec/js_routes/module_types/cjs_spec.rb
190
+ - spec/js_routes/module_types/dts/routes.spec.d.ts
191
+ - spec/js_routes/module_types/dts/test.spec.ts
192
+ - spec/js_routes/module_types/dts_spec.rb
186
193
  - spec/js_routes/module_types/esm_spec.rb
187
194
  - spec/js_routes/module_types/umd_spec.rb
188
195
  - spec/js_routes/options_spec.rb
@@ -190,6 +197,7 @@ files:
190
197
  - spec/js_routes/zzz_last_post_rails_init_spec.rb
191
198
  - spec/spec_helper.rb
192
199
  - spec/support/routes.rb
200
+ - spec/tsconfig.json
193
201
  - tsconfig.json
194
202
  - yarn.lock
195
203
  homepage: http://github.com/railsware/js-routes