Skip to content

Commit

Permalink
Fixed react bundle getting exported when export is disabled
Browse files Browse the repository at this point in the history
Caused by missing checks before react export.

Affects issues:
- #3384
  • Loading branch information
AuroraLS3 committed Jan 21, 2024
1 parent ae85f39 commit c8d0cc9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ public boolean exportPlayerJSON(UUID playerUUID, String playerName) throws Expor
}

public void exportReact() throws ExportException {
if (config.isFalse(ExportSettings.PLAYER_PAGES)
&& config.isFalse(ExportSettings.SERVER_PAGE)
&& config.isFalse(ExportSettings.PLAYERS_PAGE)) {
return;
}

Path toDirectory = config.getPageExportPath();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import extension.FullSystemExtension;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -28,12 +29,12 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

@ExtendWith(FullSystemExtension.class)
class ReactExporterTest {
Expand All @@ -50,6 +51,7 @@ static void disableSystem(PlanSystem system) {

@Test
void allReactFilesAreExported(PlanConfig config, Exporter exporter) throws ExportException, IOException {
config.set(ExportSettings.SERVER_PAGE, true);
Path exportPath = config.getPageExportPath();
exporter.exportReact();

Expand All @@ -65,4 +67,26 @@ void allReactFilesAreExported(PlanConfig config, Exporter exporter) throws Expor
.map(path -> (Executable) () -> assertTrue(filesExported.contains(path)))
.toList());
}

@Test
void noReactFilesAreExported(PlanConfig config, Exporter exporter) throws ExportException, IOException {
config.set(ExportSettings.PLAYER_PAGES, false);
config.set(ExportSettings.SERVER_PAGE, false);
config.set(ExportSettings.PLAYERS_PAGE, false);
Path exportPath = config.getPageExportPath();
Files.deleteIfExists(exportPath);

exporter.exportReact();

assertFalse(Files.exists(exportPath), () -> {
try {
return "Some files got exported: " + Files.list(exportPath)
.map(path -> path.relativize(exportPath))
.map(s -> s + "\n")
.toList();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
}

0 comments on commit c8d0cc9

Please sign in to comment.