TaskUpdateWebpack implements FallibleCommand { @Override public void execute() { try { createWebpackConfig(); } catch (IOException e) { throw new UncheckedIOException(e); } } TaskUpdateWebpack(File frontendDirectory, File webpackConfigFolder,
            File webpackOutputDirectory, String webpackTemplate,
            String webpackGeneratedTemplate, File generatedFlowImports,
            boolean useV14Bootstrapping, File flowResourcesFolder); @Override void execute();  }
@Test public void should_CreateWebpackConfigAndGeneratedConfig() throws Exception { Assert.assertFalse("No webpack config file should be present.", webpackConfig.exists()); Assert.assertFalse("No generated config file should be present.", webpackGenerated.exists()); webpackUpdater.execute(); Assert.assertTrue("webpack.config.js was not created.", webpackConfig.exists()); Assert.assertTrue("webpack.generated.js was not created.", webpackGenerated.exists()); assertWebpackConfigContent(); assertWebpackGeneratedConfigContent( "target/frontend/generated-flow-imports.js", "target/classes"); }
@Test public void execute_webpackGeneratedConfigContainsCustomFrontendDir() throws Exception { Assert.assertFalse("No webpack config file should be present.", webpackConfig.exists()); Assert.assertFalse("No generated config file should be present.", webpackGenerated.exists()); frontendFolder = new File(baseDir, "my-custom-frontend"); webpackUpdater = new TaskUpdateWebpack(frontendFolder, baseDir, new File(baseDir, TARGET + "classes"), WEBPACK_CONFIG, WEBPACK_GENERATED, new File(baseDir, DEFAULT_GENERATED_DIR + IMPORTS_NAME), false, new File(baseDir, DEFAULT_FLOW_RESOURCES_FOLDER)); webpackUpdater.execute(); Assert.assertTrue("webpack.config.js was not created.", webpackConfig.exists()); Assert.assertTrue("webpack.generated.js was not created.", webpackGenerated.exists()); assertWebpackConfigContent(); Set<String> webpackContents = Files.lines(webpackGenerated.toPath()) .map(String::trim).collect(Collectors.toSet()); Assert.assertTrue(webpackContents.contains( "const frontendFolder = require('path').resolve(__dirname, 'my-custom-frontend');")); }
@Test public void should_updateOnlyGeneratedWebpack() throws Exception { Assert.assertFalse("No webpack config file should be present.", webpackConfig.exists()); Assert.assertFalse("No generated config file should be present.", webpackGenerated.exists()); webpackUpdater.execute(); Assert.assertTrue("webpack.config.js was not created.", webpackConfig.exists()); Assert.assertTrue("webpack.generated.js was not created.", webpackGenerated.exists()); assertWebpackConfigContent(); String customString = "custom element;"; List<String> lines = FileUtils.readLines(webpackConfig, "UTF-8"); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).equals("module.exports = merge(flowDefaults,")) { lines.add(i + 1, customString); break; } } FileUtils.writeLines(webpackConfig, lines); TaskUpdateWebpack newUpdater = new TaskUpdateWebpack(frontendFolder, baseDir, new File(baseDir, "foo"), WEBPACK_CONFIG, WEBPACK_GENERATED, new File(baseDir, "bar"), false, new File(baseDir, DEFAULT_FLOW_RESOURCES_FOLDER)); newUpdater.execute(); assertWebpackGeneratedConfigContent("bar", "foo"); List<String> webpackContents = Files.lines(webpackConfig.toPath()) .collect(Collectors.toList()); Assert.assertTrue("Custom string has disappeared", webpackContents.contains(customString)); }
@Test public void should_notSetClientSideBootstrapMode_when_runningV14Bootstrapping() throws IOException { webpackUpdater.execute(); String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()) .collect(Collectors.joining("\n")); Assert.assertTrue( "useClientSideIndexFileForBootstrapping should be false by " + "default", webpackGeneratedContents .contains( "const useClientSideIndexFileForBootstrapping = false;")); }
@Test public void should_setClientSideBootstrapMode_when_runningV15Bootsrapping() throws IOException { webpackUpdater = new TaskUpdateWebpack( frontendFolder, baseDir, new File(baseDir, TARGET + "classes"), WEBPACK_CONFIG, WEBPACK_GENERATED, new File(baseDir, DEFAULT_GENERATED_DIR + IMPORTS_NAME), false, new File(baseDir, DEFAULT_FLOW_RESOURCES_FOLDER)); webpackUpdater.execute(); String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()) .collect(Collectors.joining("\n")); Assert.assertTrue( "useClientSideIndexFileForBootstrapping should be true", webpackGeneratedContents .contains( "const useClientSideIndexFileForBootstrapping = true;")); }