@@ -63,3 +63,148 @@ test("should interpret options given to the loader", async () => {
6363 const files = fs.readdirSync(outputDir);
6464 assert.ok(files.length > 0);
6565});
66+
67+ test("should throw when options.metadataSubscribers is not an array", async () => {
68+ const config = Object.assign({}, globalConfig, {
69+ output: {
70+ path: context.directory,
71+ },
72+ module: {
73+ rules: [
74+ {
75+ test: /\.jsx?/,
76+ loader: babelLoader,
77+ exclude: /node_modules/,
78+ options: {
79+ metadataSubscribers: function subscriber() {},
80+ },
81+ },
82+ ],
83+ },
84+ });
85+ const stats = await webpackAsync(config);
86+ const { errors } = stats.compilation;
87+ assert.deepEqual(errors.length, 1);
88+ const errorMessage = errors[0].message;
89+ assert.match(
90+ errorMessage,
91+ /ValidationError: Invalid options object\. Babel Loader has been initialized using an options object that does not match the API schema\./,
92+ );
93+ assert.match(errorMessage, /options\.metadataSubscribers should be an array/);
94+ });
95+
96+ test("should throw when options.customize is not a string", async () => {
97+ const config = Object.assign({}, globalConfig, {
98+ output: {
99+ path: context.directory,
100+ },
101+ module: {
102+ rules: [
103+ {
104+ test: /\.jsx?/,
105+ loader: babelLoader,
106+ exclude: /node_modules/,
107+ options: {
108+ customize: true,
109+ },
110+ },
111+ ],
112+ },
113+ });
114+ const stats = await webpackAsync(config);
115+ const { errors } = stats.compilation;
116+ assert.deepEqual(errors.length, 1);
117+ const errorMessage = errors[0].message;
118+ assert.match(
119+ errorMessage,
120+ /ValidationError: Invalid options object\. Babel Loader has been initialized using an options object that does not match the API schema\./,
121+ );
122+ assert.match(
123+ errorMessage,
124+ /options\.customize should be one of these:\s null | string/,
125+ );
126+ });
127+
128+ test("should throw when options.customize is not an absolute path", async () => {
129+ const config = Object.assign({}, globalConfig, {
130+ output: {
131+ path: context.directory,
132+ },
133+ module: {
134+ rules: [
135+ {
136+ test: /\.jsx?/,
137+ loader: babelLoader,
138+ exclude: /node_modules/,
139+ options: {
140+ customize: "./node_modules/babel-loader-customized",
141+ },
142+ },
143+ ],
144+ },
145+ });
146+ const stats = await webpackAsync(config);
147+ const { errors } = stats.compilation;
148+ assert.deepEqual(errors.length, 1);
149+ const errorMessage = errors[0].message;
150+ assert.match(
151+ errorMessage,
152+ /Error: Customized loaders must be passed as absolute paths, since babel-loader has no way to know what they would be relative to\./,
153+ );
154+ });
155+
156+ test("should warn when options.babelrc is a string", async () => {
157+ const config = Object.assign({}, globalConfig, {
158+ output: {
159+ path: context.directory,
160+ },
161+ module: {
162+ rules: [
163+ {
164+ test: /\.jsx?/,
165+ loader: babelLoader,
166+ exclude: /node_modules/,
167+ options: {
168+ babelrc: "./fixtures/babelrc",
169+ },
170+ },
171+ ],
172+ },
173+ });
174+ const stats = await webpackAsync(config);
175+ const { warnings } = stats.compilation;
176+ assert.deepEqual(warnings.length, 1);
177+ const warningMessage = warnings[0].message;
178+ assert.match(
179+ warningMessage,
180+ /The option `babelrc` should not be set to a string anymore in the babel-loader config\./,
181+ );
182+ });
183+
184+ test("should warn when options.forceEnv is set", async () => {
185+ const config = Object.assign({}, globalConfig, {
186+ output: {
187+ path: context.directory,
188+ },
189+ module: {
190+ rules: [
191+ {
192+ test: /\.jsx?/,
193+ loader: babelLoader,
194+ exclude: /node_modules/,
195+ options: {
196+ forceEnv: "production",
197+ },
198+ },
199+ ],
200+ },
201+ });
202+ const stats = await webpackAsync(config);
203+ const { warnings } = stats.compilation;
204+ assert.deepEqual(warnings.length, 1);
205+ const warningMessage = warnings[0].message;
206+ assert.match(
207+ warningMessage,
208+ /The option `forceEnv` has been removed in favor of `envName` in Babel 7\./,
209+ );
210+ });
0 commit comments