@@ -49,72 +49,68 @@ def test_can_generate_a_var_from_a_path(self):
49
49
50
50
def test_can_generate_a_webpack_config_for_a_js_component (self ):
51
51
config = get_webpack_config (HELLO_WORLD_COMPONENT_JS )
52
- self .assertTrue (config .startswith ('module.exports = {' ))
53
- self .assertIn (
54
- "context: '" + os .path .join (os .path .dirname (__file__ ), 'components' ) + "'," ,
55
- config
56
- )
57
- self .assertIn ("entry: './HelloWorld.js'," , config )
58
- self .assertIn ("output: {" , config )
59
- self .assertIn ("path: '[bundle_dir]/components'," , config )
60
- self .assertIn ("filename: 'components__HelloWorld-[hash].js'," , config )
61
- self .assertIn ("libraryTarget: 'umd'," , config )
62
- self .assertIn ("library: 'components__HelloWorld'" , config )
63
- self .assertIn ("}," , config )
64
- self .assertIn ("externals: [" , config )
65
- self .assertIn ("{" , config )
66
- self .assertIn ("'react': {" , config )
67
- self .assertIn (
68
- "commonjs2: '" + os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' , 'react' ) + "'," ,
69
- config
70
- )
71
- self .assertIn ("root: 'React'" , config )
72
- self .assertIn ("}" , config )
73
- self .assertIn ("}" , config )
74
- self .assertIn ("]," , config )
75
- self .assertIn ("devtool: 'eval'\n " , config )
76
- self .assertTrue (config .endswith ('};' ))
52
+ expected = \
53
+ """module.exports = {
54
+ context: '%s',
55
+ entry: './HelloWorld.js',
56
+ output: {
57
+ path: '[bundle_dir]/react-components',
58
+ filename: 'components__HelloWorld-[hash].js',
59
+ libraryTarget: 'umd',
60
+ library: 'components__HelloWorld'
61
+ },
62
+ externals: [{
63
+ 'react': {
64
+ commonjs2: '%s',
65
+ root: 'React'
66
+ }
67
+ }],
68
+ devtool: 'eval'
69
+ };
70
+ """ % (
71
+ os .path .join (os .path .dirname (__file__ ), 'components' ),
72
+ os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' , 'react' ),
73
+ )
74
+
75
+ self .assertEqual (config , expected )
77
76
78
77
def test_can_generate_a_webpack_config_for_a_jsx_component (self ):
79
78
config = get_webpack_config (HELLO_WORLD_COMPONENT_JSX , translate = True )
80
- self .assertTrue (config .startswith ('module.exports = {' ))
81
- self .assertIn (
82
- "context: '" + os .path .join (os .path .dirname (__file__ ), 'components' ) + "'," ,
83
- config
84
- )
85
- self .assertIn ("entry: './HelloWorld.jsx'," , config )
86
- self .assertIn ("output: {" , config )
87
- self .assertIn ("path: '[bundle_dir]/components'," , config )
88
- self .assertIn ("filename: 'components__HelloWorld-[hash].js'," , config )
89
- self .assertIn ("libraryTarget: 'umd'," , config )
90
- self .assertIn ("library: 'components__HelloWorld'" , config )
91
- self .assertIn ("}," , config )
92
- self .assertIn ("externals: [" , config )
93
- self .assertIn ("{" , config )
94
- self .assertIn ("'react': {" , config )
95
- self .assertIn (
96
- "commonjs2: '" + os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' , 'react' ) + "'," ,
97
- config
98
- )
99
- self .assertIn ("root: 'React'" , config )
100
- self .assertIn ("}" , config )
101
- self .assertIn ("}" , config )
102
- self .assertIn ("]," , config )
103
- self .assertIn ("devtool: 'eval'," , config )
104
- self .assertIn ("module: {" , config )
105
- self .assertIn ("loaders: [{" , config )
106
- self .assertIn ("test: /\.jsx$/," , config )
107
- self .assertIn ("exclude: /node_modules/," , config )
108
- self .assertIn ("loader: 'babel-loader'" , config )
109
- self .assertIn ("}]" , config )
110
- self .assertIn ("}," , config )
111
- self .assertIn ("resolveLoader: {" , config )
112
- self .assertIn (
113
- "root: '" + os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' ) + "'" ,
114
- config
115
- )
116
- self .assertIn ("}" , config )
117
- self .assertTrue (config .endswith ('};' ))
79
+ expected = \
80
+ """module.exports = {
81
+ context: '%s',
82
+ entry: './HelloWorld.jsx',
83
+ output: {
84
+ path: '[bundle_dir]/react-components',
85
+ filename: 'components__HelloWorld-[hash].js',
86
+ libraryTarget: 'umd',
87
+ library: 'components__HelloWorld'
88
+ },
89
+ externals: [{
90
+ 'react': {
91
+ commonjs2: '%s',
92
+ root: 'React'
93
+ }
94
+ }],
95
+ devtool: 'eval',
96
+ module: {
97
+ loaders: [{
98
+ test: /\.jsx$/,
99
+ exclude: /node_modules/,
100
+ loader: 'babel-loader'
101
+ }]
102
+ },
103
+ resolveLoader: {
104
+ root: '%s'
105
+ }
106
+
107
+ };
108
+ """ % (
109
+ os .path .join (os .path .dirname (__file__ ), 'components' ),
110
+ os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' , 'react' ),
111
+ os .path .join (os .path .dirname (django_react .__file__ ), 'services' , 'node_modules' ),
112
+ )
113
+ self .assertEqual (config , expected )
118
114
119
115
def test_can_generate_and_create_a_config_file (self ):
120
116
filename = get_component_config_filename (HELLO_WORLD_COMPONENT_JS )
0 commit comments