Skip to content

Commit

Permalink
fix analytics disable (fixes #2123, via #2139)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Oct 5, 2023
1 parent 4ac89f4 commit 6043391
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions allure-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ tasks.processResources {

tasks.test {
dependsOn(testWeb)
jvmArgs = listOf(
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"java.base/java.util=ALL-UNNAMED",
)
}

val allurePlugin by configurations.existing
Expand All @@ -116,6 +121,7 @@ dependencies {
testImplementation("io.qameta.allure:allure-junit-platform")
testImplementation("org.apache.commons:commons-lang3")
testImplementation("org.assertj:assertj-core")
testImplementation("org.junit-pioneer:junit-pioneer")
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core")
testImplementation("org.slf4j:slf4j-simple")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.qameta.allure.core;

import freemarker.template.Template;
import io.qameta.allure.Constants;
import io.qameta.allure.PluginConfiguration;
import io.qameta.allure.ReportGenerationException;
import io.qameta.allure.ReportStorage;
Expand All @@ -35,6 +36,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -141,7 +143,10 @@ public void generate(final Configuration configuration,
dataModel.put("reportDataFiles", reportDataFiles);
}

dataModel.put("analyticsDisable", false);
final boolean analyticsDisable = Optional.ofNullable(System.getenv(Constants.NO_ANALYTICS))
.map(Boolean::parseBoolean)
.orElse(false);
dataModel.put("analyticsDisable", analyticsDisable);
dataModel.put("reportUuid", UUID.randomUUID().toString());
dataModel.put("allureVersion", "dev");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2016-2023 Qameta Software OÜ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.core;

import io.qameta.allure.DefaultConfiguration;
import io.qameta.allure.context.FreemarkerContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junitpioneer.jupiter.SetEnvironmentVariable;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author charlie (Dmitry Baev).
*/
class ReportWebGeneratorTest {

@SetEnvironmentVariable(key = "ALLURE_NO_ANALYTICS", value = "true")
@Test
void shouldDisableAnalytics(@TempDir final Path tempDirectory) {
final DefaultConfiguration configuration = new DefaultConfiguration(Collections.singletonList(new FreemarkerContext()), Collections.emptyList());
final InMemoryReportStorage reportStorage = new InMemoryReportStorage();
new ReportWebGenerator()
.generate(
configuration,
reportStorage,
tempDirectory
);

final Path indexHtml = tempDirectory.resolve("index.html");

assertThat(indexHtml)
.isRegularFile()
.content(StandardCharsets.UTF_8)
.doesNotContain("googletagmanager");
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ subprojects {
dependency("org.assertj:assertj-core:3.24.2")
dependency("org.eclipse.jetty:jetty-server:9.4.51.v20230217")
dependency("org.freemarker:freemarker:2.3.32")
dependency("org.junit-pioneer:junit-pioneer:2.1.0")
dependency("org.mockito:mockito-core:5.5.0")
dependency("org.projectlombok:lombok:1.18.30")
dependency("org.zeroturnaround:zt-zip:1.16")
Expand Down

0 comments on commit 6043391

Please sign in to comment.