Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Fix a bug in the custom name support for the divolte.js tracking script.
Browse files Browse the repository at this point in the history
Also adds some tests for this, as well as verifying that the Javascript still compiles with the logging/debug options enabled.

(cherry picked from commit 6f19931)
  • Loading branch information
asnare committed Sep 7, 2016
1 parent 33b110c commit 8e0dee4
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 GoDataDriven B.V.
* Copyright 2016 GoDataDriven B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,7 @@ public static TrackingJavaScriptResource create(final ValidatedConfiguration vc,
final String sourceName) throws IOException {
final BrowserSourceConfiguration browserSourceConfiguration =
vc.configuration().getSourceConfiguration(sourceName, BrowserSourceConfiguration.class);
return new TrackingJavaScriptResource(browserSourceConfiguration.javascript.name,
return new TrackingJavaScriptResource("divolte.js",
createScriptConstants(browserSourceConfiguration),
browserSourceConfiguration.javascript.debug);
}
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/io/divolte/server/SeleniumJavaScriptTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 GoDataDriven B.V.
* Copyright 2016 GoDataDriven B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -261,6 +261,18 @@ public void shouldPickupProvidedPageViewIdFromHash() throws Exception {
assertEquals("supercalifragilisticexpialidocious0", eventData.eventId);
}

@Test
public void shouldSupportCustomJavascriptName() throws Exception {
doSetUp("selenium-test-custom-javascript-name.conf");
Preconditions.checkState(null != driver && null != server);

driver.get(urlOf(CUSTOM_JAVASCRIPT_NAME));
final EventPayload payload = server.waitForEvent();
final DivolteEvent eventData = payload.event;

assertEquals("pageView", eventData.eventType.get());
}

@Test
public void shouldUseConfiguredEventSuffix() throws Exception {
doSetUp("selenium-test-custom-event-suffix.conf");
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/divolte/server/SeleniumTestBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 GoDataDriven B.V.
* Copyright 2016 GoDataDriven B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -126,6 +126,7 @@ public enum TEST_PAGES {
BASIC("test-basic-page"),
BASIC_COPY("test-basic-page-copy"),
PAGE_VIEW_SUPPLIED("test-basic-page-provided-pv-id"),
CUSTOM_JAVASCRIPT_NAME("test-custom-javascript-name"),
CUSTOM_PAGE_VIEW("test-custom-page-view");

private final String resourceName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 GoDataDriven B.V.
* Copyright 2016 GoDataDriven B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,29 +16,52 @@

package io.divolte.server.js;

import com.google.common.collect.ImmutableList;
import com.typesafe.config.ConfigFactory;
import io.divolte.server.config.ValidatedConfiguration;
import io.undertow.util.ETag;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import javax.annotation.ParametersAreNonnullByDefault;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

@RunWith(Parameterized.class)
@ParametersAreNonnullByDefault
public class TrackingJavaScriptResourceTest {

private final Config config = ConfigFactory.load();
@Parameterized.Parameters(name = "{index}: {0} configuration")
public static Iterable<Object[]> configurations() {
return ImmutableList.of(
new Object[] { "default", ConfigFactory.load() },
new Object[] { "non-default-name", ConfigFactory.load("browser-source-custom-javascript-name.conf")},
new Object[] { "logging-enabled", ConfigFactory.load("browser-source-javascript-logging.conf")},
new Object[] { "verbose-enabled", ConfigFactory.load("browser-source-javascript-debugging.conf")}
);
}

private final Config config;

private TrackingJavaScriptResource trackingJavaScript;

public TrackingJavaScriptResourceTest(final String name, final Config config) {
this.config = Objects.requireNonNull(config);
}

@Before
public void setup() throws IOException {
// Essential test to ensure at build-time that our JavaScript can be compiled.
Expand Down
29 changes: 29 additions & 0 deletions src/test/resources/browser-source-custom-javascript-name.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright 2016 GoDataDriven B.V.
//
// 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.
//

// Specify a browser source that uses a custom name for the Javascript resource.
divolte {
sources.browser {
type = browser
javascript.name = dvt.js
}

mappings.test = {
sources = [browser]
// Need at least one sink.
sinks = [hdfs]
}
}
29 changes: 29 additions & 0 deletions src/test/resources/browser-source-javascript-debugging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright 2016 GoDataDriven B.V.
//
// 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.
//

// Specify a browser source that uses a custom name for the Javascript resource.
divolte {
sources.browser {
type = browser
javascript.debug = true
}

mappings.test = {
sources = [browser]
// Need at least one sink.
sinks = [hdfs]
}
}
29 changes: 29 additions & 0 deletions src/test/resources/browser-source-javascript-logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright 2016 GoDataDriven B.V.
//
// 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.
//

// Specify a browser source that uses a custom name for the Javascript resource.
divolte {
sources.browser {
type = browser
javascript.logging = true
}

mappings.test = {
sources = [browser]
// Need at least one sink.
sinks = [hdfs]
}
}
21 changes: 21 additions & 0 deletions src/test/resources/selenium-test-custom-javascript-name.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright 2016 GoDataDriven B.V.
//
// 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.
//

// Instead of using the default 'csc-event' endpoint, use a different value.
divolte.sources.browser {
type = browser
javascript.name = dvt.js
}
30 changes: 30 additions & 0 deletions src/test/resources/static/quirks/test-custom-javascript-name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ Copyright 2016 GoDataDriven B.V.
~
~ 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.
-->

<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DVT</title>

<!-- Suppress favicon requests. -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
<script src="/dvt.js" defer async></script>
</body>
</html>
31 changes: 31 additions & 0 deletions src/test/resources/static/strict/test-custom-javascript-name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<!--
~ Copyright 2016 GoDataDriven B.V.
~
~ 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.
-->

<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DVT</title>

<!-- Suppress favicon requests. -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
<script src="/dvt.js" defer async></script>
</body>
</html>

0 comments on commit 8e0dee4

Please sign in to comment.