use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.
the class AbstractNodeUpdatePackagesTest method generatePackageJson_sameDependenciesInDifferentOrder_updaterIsNotModified.
@Test
public void generatePackageJson_sameDependenciesInDifferentOrder_updaterIsNotModified() throws IOException {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
Map<String, String> packages = new HashMap<>();
packages.put("@polymer/iron-list", "3.0.2");
packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
packages.put("@vaadin/vaadin-checkbox", "2.2.10");
packages.put("@polymer/iron-icon", "3.0.1");
packages.put("@vaadin/vaadin-time-picker", "2.0.2");
Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
packageCreator.execute();
packageUpdater.execute();
// Shuffle the dependencies.
JsonObject json = getPackageJson(this.packageJson);
JsonObject dependencies = json.getObject(DEPENDENCIES);
List<String> dependencyKeys = Arrays.asList(dependencies.keys());
Collections.shuffle(dependencyKeys);
JsonObject newDependencies = Json.createObject();
dependencyKeys.forEach(key -> newDependencies.put(key, dependencies.getString(key)));
json.put(DEPENDENCIES, newDependencies);
Files.write(this.packageJson.toPath(), Collections.singletonList(stringify(json)));
// generate it one more time, the content will be different since
// packageCreator has not added its content
packageUpdater.execute();
Assert.assertFalse("Modification flag should be false when no dependencies changed.", packageUpdater.modified);
}
use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.
the class AbstractNodeUpdatePackagesTest method updatedPackageJson_noDependencies_creatorAndUpdatedIsMarkedModified.
@Test
public void updatedPackageJson_noDependencies_creatorAndUpdatedIsMarkedModified() {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
Map<String, String> packages = new HashMap<>();
Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
packageCreator.execute();
packageUpdater.execute();
Assert.assertTrue("Modification flag should be true when main package was created.", packageCreator.modified);
Assert.assertTrue("Modification flag should be true as we should have updated the hash for default dependencies.", packageUpdater.modified);
}
use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.
the class UpdateThemedImportsTest method setup.
@Before
public void setup() throws Exception {
File tmpRoot = temporaryFolder.getRoot();
frontendDirectory = new File(tmpRoot, DEFAULT_FRONTEND_DIR);
nodeModulesPath = new File(tmpRoot, NODE_MODULES);
generatedPath = new File(tmpRoot, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
importsFile = new File(generatedPath, IMPORTS_NAME);
Assert.assertTrue(nodeModulesPath.mkdirs());
createImport("./src/subfolder/sub-template.js", "");
createImport("./src/client-side-template.js", "import 'xx' from './subfolder/sub-template.js';" + "import '@vaadin/vaadin-button/src/vaadin-button.js'");
createImport("./src/client-side-no-themed-template.js", "");
createImport("./src/main-template.js", "import 'xx' from './client-side-template.js';" + "import \"./client-side-no-themed-template.js\";" + "import './src/wrong-themed-template.js';" + "import '@vaadin/vaadin-button/src/vaadin-button.js'");
// create themed modules
createImport("./theme/myTheme/subfolder/sub-template.js", "");
createImport("./theme/myTheme/client-side-template.js", "");
createImport("./theme/myTheme/main-template.js", "");
// wrong-themed-template.js should not be resolved inside node_modules.
// It should be searched only inside frontend directory
createImport("theme/myTheme/wrong-themed-template.js", "");
// create css files to avoid exception when files not found during the
// test
createImport("./foo.css", "");
createImport("@vaadin/vaadin-mixed-component/bar.css", "");
// make external component's module and its themed version
createImport("@vaadin/vaadin-button/src/vaadin-button.js", "");
createImport("@vaadin/vaadin-button/theme/myTheme/vaadin-button.js", "");
ClassFinder finder = getClassFinder();
FrontendDependencies deps = new FrontendDependencies(finder) {
@Override
public List<String> getModules() {
return Stream.of("./src/main-template.js").collect(Collectors.toList());
}
@Override
public Set<String> getScripts() {
return Collections.emptySet();
}
@Override
public AbstractTheme getTheme() {
return new MyTheme();
}
@Override
public ThemeDefinition getThemeDefinition() {
return new ThemeDefinition(MyTheme.class, "", "");
}
};
updater = new TaskUpdateImports(finder, deps, cf -> null, tmpRoot, generatedPath, frontendDirectory, null, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class));
}
use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.
the class AbstractNodeUpdatePackagesTest method removedFrameworkDependencies_dependencyIsRemoved.
@Test
public void removedFrameworkDependencies_dependencyIsRemoved() throws IOException {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
Map<String, String> packages = new HashMap<>();
packages.put("@polymer/iron-list", "3.0.2");
packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
packages.put("@vaadin/vaadin-checkbox", "2.2.10");
packages.put("@polymer/iron-icon", "3.0.1");
packages.put("@vaadin/vaadin-time-picker", "2.0.2");
Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
packageCreator.execute();
packageUpdater.execute();
packages.remove("@vaadin/vaadin-checkbox");
JsonObject dependencies = getPackageJson(packageJson).getObject(DEPENDENCIES);
Assert.assertTrue("vaadin-checkbox is missing from the dependencies", dependencies.hasKey("@vaadin/vaadin-checkbox"));
dependencies = getPackageJson(packageJson).getObject(VAADIN_DEP_KEY).getObject(DEPENDENCIES);
Assert.assertTrue("vaadin-checkbox is missing from vaadin.dependencies", dependencies.hasKey("@vaadin/vaadin-checkbox"));
// generate it one more time, this should remove the checkbox
packageUpdater.execute();
dependencies = getPackageJson(packageJson).getObject(DEPENDENCIES);
Assert.assertFalse("vaadin-checkbox is still available in the dependencies", dependencies.hasKey("@vaadin/vaadin-checkbox"));
dependencies = getPackageJson(packageJson).getObject(VAADIN_DEP_KEY).getObject(DEPENDENCIES);
Assert.assertFalse("vaadin-checkbox is still available in vaadin.dependencies", dependencies.hasKey("@vaadin/vaadin-checkbox"));
}
use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.
the class AbstractNodeUpdatePackagesTest method userAddedDependencies_notCleanedByUpdater.
@Test
public void userAddedDependencies_notCleanedByUpdater() throws IOException {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
Map<String, String> packages = new HashMap<>();
packages.put("@polymer/iron-list", "3.0.2");
packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
packages.put("@vaadin/vaadin-checkbox", "2.2.10");
packages.put("@polymer/iron-icon", "3.0.1");
packages.put("@vaadin/vaadin-time-picker", "2.0.2");
Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
packageCreator.execute();
JsonObject json = getPackageJson(packageJson);
json.getObject(DEPENDENCIES).put("@custom/timer", "3.3.0");
Files.write(packageJson.toPath(), Collections.singletonList(json.toJson()));
packageUpdater.execute();
JsonObject dependencies = getPackageJson(packageJson).getObject(DEPENDENCIES);
Assert.assertTrue(dependencies.hasKey("@custom/timer"));
Assert.assertEquals("3.3.0", dependencies.getString("@custom/timer"));
}
Aggregations