Skip to content

Commit a117d77

Browse files
committed
test: add tests for finding babel config file
1 parent 2b05775 commit a117d77

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lib/build.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,44 @@ describe('build', () => {
8989
'.custom',
9090
]);
9191
});
92+
93+
describe("babel config file resolution", () => {
94+
const findBabelLoaderRule = rules => rules.find(rule => rule.use.loader.includes("babel-loader"));
95+
96+
it("should alter the default babelOpts when no valid babel config file is found", async () => {
97+
setupFunction("", "not-babel.config.js");
98+
99+
const stats = await build.run(functions);
100+
const babelLoaderRuleOptions = findBabelLoaderRule(stats.compilation.options.module.rules).use.options;
101+
102+
expect(babelLoaderRuleOptions.presets).toBeDefined();
103+
expect(babelLoaderRuleOptions.plugins).toBeDefined();
104+
});
105+
106+
it("should not alter the default babelOpts when a valid babel config file is found in same directory as the functions directory", async () => {
107+
setupFunction("", "babel.config.js");
108+
109+
const stats = await build.run(functions);
110+
const babelLoaderRuleOptions = findBabelLoaderRule(stats.compilation.options.module.rules).use.options;
111+
112+
expect(babelLoaderRuleOptions.presets).toBeUndefined();
113+
expect(babelLoaderRuleOptions.plugins).toBeUndefined();
114+
});
115+
116+
it("should not alter the default babelOpts when a valid babel config is found in directory above the functions directory", async () => {
117+
setupFunction("", "babel.config.js");
118+
119+
const functionsSubDir = path.join(functions, "subdir");
120+
121+
fs.mkdirSync(functionsSubDir);
122+
fs.writeFileSync(path.join(functionsSubDir, "index.js"), "");
123+
124+
const stats = await build.run(functionsSubDir);
125+
const babelLoaderRuleOptions = findBabelLoaderRule(stats.compilation.options.module.rules).use.options;
126+
127+
expect(babelLoaderRuleOptions.presets).toBeUndefined();
128+
expect(babelLoaderRuleOptions.plugins).toBeUndefined();
129+
});
130+
})
92131
});
93132
});

0 commit comments

Comments
 (0)