File tree 4 files changed +83
-8
lines changed
4 files changed +83
-8
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ impl RequireJsBuildConfig {
136
136
/// children: []
137
137
/// urls: ["/"]
138
138
/// "#;
139
- /// let rjx2 = rjx.with_bundle_config( bundle_config_str.into(), &vec![]);
139
+ /// let rjx2 = rjx.create_modules(& bundle_config_str.into(), &vec![]);
140
140
/// assert_eq!(rjx2.modules.expect("has modules"), vec![
141
141
/// BuildModule {
142
142
/// name: "requirejs/require".to_string(),
@@ -155,9 +155,9 @@ impl RequireJsBuildConfig {
155
155
/// ]);
156
156
/// ```
157
157
///
158
- pub fn with_bundle_config (
158
+ pub fn create_modules (
159
159
mut self ,
160
- bundle_config : BundleConfig ,
160
+ bundle_config : & BundleConfig ,
161
161
req_log : & Vec < ModuleData >
162
162
) -> RequireJsBuildConfig {
163
163
self . modules = Some ( modules:: generate_modules ( req_log, bundle_config) ) ;
Original file line number Diff line number Diff line change @@ -40,19 +40,18 @@ pub struct ModuleData {
40
40
///
41
41
pub fn generate_modules (
42
42
req_log : & Vec < ModuleData > ,
43
- config : impl Into < BundleConfig > ,
43
+ config : & BundleConfig ,
44
44
) -> Vec < BuildModule > {
45
45
let mut modules: Vec < BuildModule > = vec ! [ BuildModule {
46
46
name: "requirejs/require" . into( ) ,
47
47
include: vec![ ] ,
48
48
exclude: vec![ ] ,
49
49
create: false ,
50
50
} ] ;
51
- let conf = config. into ( ) ;
52
51
collect (
53
52
& mut modules,
54
53
req_log,
55
- & conf . bundles ,
54
+ & config . bundles ,
56
55
vec ! [ "requirejs/require" . into( ) ] ,
57
56
) ;
58
57
modules. to_vec ( )
@@ -168,7 +167,7 @@ fn test_create_modules() {
168
167
"# . into ( ) ;
169
168
let reqs: Vec < ModuleData > =
170
169
serde_json:: from_str ( include_str ! ( "../test/fixtures/example-reqs.json" ) ) . unwrap ( ) ;
171
- let out = generate_modules ( & reqs, c) ;
170
+ let out = generate_modules ( & reqs, & c) ;
172
171
173
172
assert_eq ! (
174
173
out[ 0 ] ,
Original file line number Diff line number Diff line change
1
+ extern crate rjs;
2
+ extern crate from_file;
3
+ extern crate serde_json;
4
+
5
+ use rjs:: { RequireJsBuildConfig , RequireJsClientConfig , bundle_config} ;
6
+
7
+ #[ test]
8
+ fn test_all_strings ( ) {
9
+ let rjs_config = r#"
10
+ (function() {
11
+ var config = {
12
+ shim: {
13
+ backbone: ["jquery"]
14
+ }
15
+ }
16
+ })();
17
+ "# ;
18
+ let bundle_config = r#"
19
+ {"bundles": [{"name": "main", "children": [], "urls": ["/"]}]}
20
+ "# ;
21
+ let req_log = r#"
22
+ [
23
+ {
24
+ "url": "https://example.com/jquery",
25
+ "id": "jquery",
26
+ "referrer": "/"
27
+ }
28
+ ]
29
+ "# ;
30
+ let expected = r#"
31
+ {
32
+ "generateSourceMaps": true,
33
+ "inlineText": true,
34
+ "optimize": "uglify",
35
+ "deps": [],
36
+ "map": {},
37
+ "config": {},
38
+ "shim": {
39
+ "backbone": [
40
+ "jquery"
41
+ ]
42
+ },
43
+ "paths": {},
44
+ "modules": [
45
+ {
46
+ "name": "requirejs/require",
47
+ "include": [],
48
+ "exclude": [],
49
+ "create": false
50
+ },
51
+ {
52
+ "name": "main",
53
+ "include": [
54
+ "jquery"
55
+ ],
56
+ "exclude": [
57
+ "requirejs/require"
58
+ ],
59
+ "create": true
60
+ }
61
+ ]
62
+ }
63
+ "# ;
64
+
65
+ let rjs_build = RequireJsBuildConfig :: from_generated_string ( rjs_config) . expect ( "sup" ) ;
66
+ let config = bundle_config:: BundleConfig :: from_json_string ( bundle_config) . expect ( "bundle config parse" ) ;
67
+ let req_log: Vec < rjs:: modules:: ModuleData > = serde_json:: from_str ( req_log) . expect ( "serde" ) ;
68
+
69
+ let next_build = rjs_build. create_modules ( & config, & req_log) ;
70
+ let as_string = next_build. to_string ( ) . expect ( "must serialize" ) ;
71
+
72
+ let actual_as_value: serde_json:: Value = serde_json:: from_str ( & as_string) . expect ( "serde actual" ) ;
73
+ let expected_as_value: serde_json:: Value = serde_json:: from_str ( & expected) . expect ( "serde expected" ) ;
74
+
75
+ assert_eq ! ( actual_as_value, expected_as_value) ;
76
+ }
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ pub fn gather_state(
48
48
let mut c = client_config. paths . clone ( ) ;
49
49
derived_build_config. paths = RequireJsBuildConfig :: strip_paths ( & c) ;
50
50
51
- let derived_build_config = derived_build_config. with_bundle_config ( bundle_config, & filtered) ;
51
+ let derived_build_config = derived_build_config. create_modules ( & bundle_config, & filtered) ;
52
52
53
53
Ok ( derived_build_config)
54
54
}
You can’t perform that action at this time.
0 commit comments