Search in sources :

Example 1 with FrontendDependenciesScannerFactory

use of com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory in project flow by vaadin.

the class NodeUpdateImportsTest method noFallBackScanner_fallbackIsNotGenerated.

@Test
public void noFallBackScanner_fallbackIsNotGenerated() throws IOException {
    Stream<Class<?>> classes = Stream.concat(Stream.of(NodeTestComponents.class.getDeclaredClasses()), Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()));
    ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
    updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> null, tmpRoot, generatedPath, frontendDirectory, tokenFile, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {

        @Override
        Logger log() {
            return logger;
        }
    };
    updater.execute();
    assertTrue(importsFile.exists());
    String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    // fallback chunk load function is not generated
    MatcherAssert.assertThat(mainContent, CoreMatchers.not(CoreMatchers.containsString("window.Vaadin.Flow.loadFallback = function loadFallback(){")));
    Assert.assertFalse(fallBackImportsFile.exists());
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Json(elemental.json.Json) JsonArray(elemental.json.JsonArray) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) IMPORTS_D_TS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) URLClassLoader(java.net.URLClassLoader) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 2 with FrontendDependenciesScannerFactory

use of com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory in project flow by vaadin.

the class NodeUpdateImportsTest method tokenFileIsStable.

@Test
public void tokenFileIsStable() throws Exception {
    Stream<Class<?>> classes = Stream.concat(Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()), Stream.of(NodeTestComponents.class.getDeclaredClasses()));
    ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
    JsonObject fallBackData = Json.createObject();
    updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> new FrontendDependenciesScannerFactory().createScanner(true, finder, true), tmpRoot, generatedPath, frontendDirectory, tokenFile, fallBackData, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {

        @Override
        Logger log() {
            return logger;
        }
    };
    updater.execute();
    JsonObject fallback = fallBackData.getObject("chunks").getObject("fallback");
    JsonArray jsModules = fallback.getArray("jsModules");
    JsonArray cssImports = fallback.getArray("cssImports");
    String expectedJsModules = "[\"@polymer/e.js\",\"@polymer/D.js\",\"@polymer/c.js\",\"@polymer/b.js\",\"@polymer/a.js\",\"./extra-javascript.js\"]";
    String expectedCssImports = "[{\"value\":\"./b-css.css\"},{\"include\":\"a-a\",\"value\":\"./a-css.css\"},{\"include\":\"extra-bar\",\"themeFor\":\"extra-foo\",\"value\":\"./extra-css.css\"}]";
    Assert.assertEquals(expectedJsModules, jsModules.toJson());
    Assert.assertEquals(expectedCssImports, cssImports.toJson());
    String actual = FileUtils.readFileToString(tokenFile, StandardCharsets.UTF_8);
    String expected = // 
    "{\n" + // 
    "  \"chunks\": {\n" + // 
    "    \"fallback\": {\n" + // 
    "      \"jsModules\": [\n" + // 
    "        \"@polymer/e.js\",\n" + // 
    "        \"@polymer/D.js\",\n" + // 
    "        \"@polymer/c.js\",\n" + // 
    "        \"@polymer/b.js\",\n" + // 
    "        \"@polymer/a.js\",\n" + // 
    "        \"./extra-javascript.js\"\n" + // 
    "      ],\n" + // 
    "      \"cssImports\": [\n" + // 
    "        {\n" + // 
    "          \"value\": \"./b-css.css\"\n" + // 
    "        },\n" + // 
    "        {\n" + // 
    "          \"include\": \"a-a\",\n" + // 
    "          \"value\": \"./a-css.css\"\n" + // 
    "        },\n" + // 
    "        {\n" + // 
    "          \"include\": \"extra-bar\",\n" + // 
    "          \"themeFor\": \"extra-foo\",\n" + // 
    "          \"value\": \"./extra-css.css\"\n" + // 
    "        }\n" + // 
    "      ]\n" + // 
    "    }\n" + // 
    "  }\n" + "}";
    Assert.assertEquals(expected, actual);
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Json(elemental.json.Json) JsonArray(elemental.json.JsonArray) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) IMPORTS_D_TS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) JsonObject(elemental.json.JsonObject) Logger(org.slf4j.Logger) JsonArray(elemental.json.JsonArray) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) URLClassLoader(java.net.URLClassLoader) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Test(org.junit.Test)

Example 3 with FrontendDependenciesScannerFactory

use of com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory in project flow by vaadin.

the class NodeUpdateImportsTest method emptyByteCodeScannerData_themeIsDiscovered_fallbackIsGenerated.

@Test
public void emptyByteCodeScannerData_themeIsDiscovered_fallbackIsGenerated() throws IOException {
    ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), EmptyByteScannerDataTestComponents.class.getDeclaredClasses());
    updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> new FrontendDependenciesScannerFactory().createScanner(true, finder, true), tmpRoot, generatedPath, frontendDirectory, tokenFile, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {

        @Override
        Logger log() {
            return logger;
        }
    };
    updater.execute();
    assertTrue(importsFile.exists());
    String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    // ============== check main generated imports file ============
    // Contains theme lines
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("export const addCssBlock = function(block, before = false) {"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("addCssBlock('<custom-style>foo</custom-style>', true);"));
    // fallback chunk load function is generated
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("fallbacks[thisScript.getAttribute('data-app-id')].loadFallback = function loadFallback() {"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("return import('./generated-flow-imports-fallback.js');"));
    // ============== check fallback generated imports file ============
    String fallBackContent = FileUtils.readFileToString(fallBackImportsFile, Charset.defaultCharset());
    // Does not Contains theme lines
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("const div = document.createElement('div');")));
    // Contains CSS import lines from CP not discovered by byte
    // scanner
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import $cssFromFile_0 from 'Frontend/foo.css';"));
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("registerStyles('', $css_0, {include: 'bar', moduleId: 'baz'});"));
    // Contains JS module imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import '@vaadin/vaadin-lumo-styles/icons.js';"));
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import 'Frontend/common-js-file.js';"));
    // Contains Javascript imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import '@vaadin/flow-frontend/ExampleConnector.js';"));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Json(elemental.json.Json) JsonArray(elemental.json.JsonArray) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) IMPORTS_D_TS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) URLClassLoader(java.net.URLClassLoader) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 4 with FrontendDependenciesScannerFactory

use of com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory in project flow by vaadin.

the class NodeUpdateImportsTest method noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists.

@Test
public void noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists() throws Exception {
    Stream<Class<?>> classes = Stream.concat(Stream.of(NodeTestComponents.class.getDeclaredClasses()), Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()));
    ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
    // create fallback imports file:
    // it is present after generated but the user is now running
    // everything without fallback. The file should not be included into
    // the imports
    fallBackImportsFile.mkdirs();
    fallBackImportsFile.createNewFile();
    Assert.assertTrue(fallBackImportsFile.exists());
    updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> null, tmpRoot, generatedPath, frontendDirectory, tokenFile, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {

        @Override
        Logger log() {
            return logger;
        }
    };
    updater.execute();
    assertTrue(importsFile.exists());
    String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    // fallback file is not imported in generated-flow-imports
    MatcherAssert.assertThat(mainContent, CoreMatchers.not(CoreMatchers.containsString(FrontendUtils.FALLBACK_IMPORTS_NAME)));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Json(elemental.json.Json) JsonArray(elemental.json.JsonArray) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) IMPORTS_D_TS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) URLClassLoader(java.net.URLClassLoader) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with FrontendDependenciesScannerFactory

use of com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory in project flow by vaadin.

the class NodeUpdateImportsTest method extraComponentsInCP_componentsAreNotDiscoveredByMainScannerWrittenByFallback_fallbackIsGenerated.

@Test
public void extraComponentsInCP_componentsAreNotDiscoveredByMainScannerWrittenByFallback_fallbackIsGenerated() throws IOException {
    Stream<Class<?>> classes = Stream.concat(Stream.of(NodeTestComponents.class.getDeclaredClasses()), Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()));
    ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
    JsonObject fallBackData = Json.createObject();
    updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> new FrontendDependenciesScannerFactory().createScanner(true, finder, true), tmpRoot, generatedPath, frontendDirectory, tokenFile, fallBackData, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {

        @Override
        Logger log() {
            return logger;
        }
    };
    updater.execute();
    assertTrue(importsFile.exists());
    String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    // ============== check main generated imports file ============
    // Contains theme lines
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("export const addCssBlock = function(block, before = false) {"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("addCssBlock('<custom-style><style include=\"lumo-color lumo-typography\"></style></custom-style>', true);"));
    // Contains CSS import lines
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import $cssFromFile_0 from '@vaadin/vaadin-mixed-component/bar.css';"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("addCssBlock(`<style>${$css_0}</style>`);"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import $cssFromFile_5 from 'Frontend/foo.css';"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("registerStyles('foo-bar', $css_5, {moduleId: 'flow_css_mod'});"));
    // Contains theme imports
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import '@vaadin/vaadin-lumo-styles/color.js';"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import '@vaadin/vaadin-lumo-styles/typography.js';"));
    // Contains JS module imports
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import '@polymer/iron-icon/iron-icon.js';"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import '3rdparty/component.js';"));
    // Contains Javascript imports
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import 'javascript/a.js';"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("import 'javascript/b.js';"));
    // fallback chunk load function is generated
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("fallbacks[thisScript.getAttribute('data-app-id')].loadFallback = function loadFallback() {"));
    MatcherAssert.assertThat(mainContent, CoreMatchers.containsString("return import('./generated-flow-imports-fallback.js');"));
    assertTrue(fallBackImportsFile.exists());
    // ============== check fallback generated imports file ============
    String fallBackContent = FileUtils.readFileToString(fallBackImportsFile, Charset.defaultCharset());
    // Does not Contains theme lines
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("const div = document.createElement('div');")));
    // Does not contains theme imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("import '@vaadin/vaadin-lumo-styles/color.js';")));
    // Does not contains CSS import lines
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("import $cssFromFile_0 from '@vaadin/vaadin-mixed-component/bar.css';")));
    // Contain lines to import exported modules from main file
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("export const addCssBlock = function(block, before = false) {"));
    // Contains CSS import lines from CP not discovered by byte scanner
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import $cssFromFile_0 from 'Frontend/b-css.css';"));
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("registerStyles('extra-foo', $css_2, {include: 'extra-bar', moduleId: 'fallback_flow_css_mod'});"));
    // Does not contains JS module imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("import '@polymer/iron-icon/iron-icon.js';")));
    // Contains JS module imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import '@polymer/a.js';"));
    // Does not contain Javascript imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.not(CoreMatchers.containsString("import 'javascript/a.js';")));
    // Contains Javascript imports
    MatcherAssert.assertThat(fallBackContent, CoreMatchers.containsString("import 'Frontend/extra-javascript.js';"));
    // ============== check token file with fallback chunk data ============
    String tokenContent = FileUtils.readFileToString(tokenFile, Charset.defaultCharset());
    JsonObject object = Json.parse(tokenContent);
    assertTokenFileWithFallBack(object);
    assertTokenFileWithFallBack(fallBackData);
    // ============== check definition file ============
    assertTrue(importsDefinitionFile.exists());
    String definitionContent = FileUtils.readFileToString(importsDefinitionFile, Charset.defaultCharset());
    MatcherAssert.assertThat(definitionContent, CoreMatchers.containsString("export declare const addCssBlock: (block: string, before?: boolean) => void;"));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Json(elemental.json.Json) JsonArray(elemental.json.JsonArray) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) IMPORTS_D_TS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) FrontendDependenciesScannerFactory(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory) URLClassLoader(java.net.URLClassLoader) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) JsonObject(elemental.json.JsonObject) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

FeatureFlags (com.vaadin.experimental.FeatureFlags)5 TARGET (com.vaadin.flow.server.Constants.TARGET)5 DEFAULT_FRONTEND_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR)5 DEFAULT_GENERATED_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR)5 FLOW_NPM_PACKAGE_NAME (com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME)5 IMPORTS_D_TS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME)5 IMPORTS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME)5 NODE_MODULES (com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES)5 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)5 DefaultClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder)5 FrontendDependenciesScannerFactory (com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory)5 Json (elemental.json.Json)5 JsonArray (elemental.json.JsonArray)5 JsonObject (elemental.json.JsonObject)5 File (java.io.File)5 IOException (java.io.IOException)5 URLClassLoader (java.net.URLClassLoader)5 Charset (java.nio.charset.Charset)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Paths (java.nio.file.Paths)5