Skip to content

Commit ea96657

Browse files
committed
simple test for isssue #1001
1 parent 4ecfee4 commit ea96657

6 files changed

Lines changed: 10971 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2002-2025 Gargoyle Software Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.htmlunit.libraries;
16+
17+
import org.eclipse.jetty.server.Server;
18+
import org.htmlunit.WebClient;
19+
import org.htmlunit.WebServerTestCase;
20+
import org.junit.jupiter.api.AfterAll;
21+
import org.junit.jupiter.api.BeforeAll;
22+
import org.junit.jupiter.api.Test;
23+
24+
/**
25+
* A simple smoke test for jasmine 3.9.0.
26+
* See issue #1001 for more.
27+
*
28+
* @author Ronald Brill
29+
*/
30+
public class Jasmine3x9x0SmokeTest extends WebServerTestCase {
31+
32+
/** The server. */
33+
protected static Server SERVER_;
34+
35+
/**
36+
* @throws Exception if an error occurs
37+
*/
38+
@BeforeAll
39+
public static void startSesrver() throws Exception {
40+
SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/jasmine/jasmine_3.9.0", null);
41+
}
42+
43+
/**
44+
* @throws Exception if an error occurs
45+
*/
46+
@AfterAll
47+
public static void stopServer() throws Exception {
48+
if (SERVER_ != null) {
49+
SERVER_.stop();
50+
SERVER_.destroy();
51+
SERVER_ = null;
52+
}
53+
}
54+
55+
/**
56+
* @throws Exception if an error occurs
57+
*/
58+
@Test
59+
public void shouldTestJavaScript() throws Exception {
60+
final WebClient webClient = getWebClient();
61+
62+
webClient.getPage(URL_FIRST + "smoketest.html");
63+
}
64+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
This file starts the process of "booting" Jasmine. It initializes Jasmine,
3+
makes its globals available, and creates the env. This file should be loaded
4+
after `jasmine.js` and `jasmine_html.js`, but before `boot1.js` or any project
5+
source files or spec files are loaded.
6+
*/
7+
(function() {
8+
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
9+
10+
/**
11+
* ## Require & Instantiate
12+
*
13+
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
14+
*/
15+
var jasmine = jasmineRequire.core(jasmineRequire),
16+
global = jasmine.getGlobal();
17+
global.jasmine = jasmine;
18+
19+
/**
20+
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
21+
*/
22+
jasmineRequire.html(jasmine);
23+
24+
/**
25+
* Create the Jasmine environment. This is used to run all specs in a project.
26+
*/
27+
var env = jasmine.getEnv();
28+
29+
/**
30+
* ## The Global Interface
31+
*
32+
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
33+
*/
34+
var jasmineInterface = jasmineRequire.interface(jasmine, env);
35+
36+
/**
37+
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
38+
*/
39+
for (var property in jasmineInterface) {
40+
global[property] = jasmineInterface[property];
41+
}
42+
}());
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
This file finishes "booting" Jasmine, performing all of the necessary
3+
initialization before executing the loaded environment and all of a project's
4+
specs. This file should be loaded after `boot0.js` but before any project
5+
source files or spec files are loaded. Thus this file can also be used to
6+
customize Jasmine for a project.
7+
8+
If a project is using Jasmine via the standalone distribution, this file can
9+
be customized directly. If you only wish to configure the Jasmine env, you
10+
can load another file that calls `jasmine.getEnv().configure({...})`
11+
after `boot0.js` is loaded and before this file is loaded.
12+
*/
13+
14+
(function() {
15+
var env = jasmine.getEnv();
16+
17+
/**
18+
* ## Runner Parameters
19+
*
20+
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
21+
*/
22+
23+
var queryString = new jasmine.QueryString({
24+
getWindowLocation: function() { return window.location; }
25+
});
26+
27+
var filterSpecs = !!queryString.getParam("spec");
28+
29+
var config = {
30+
failFast: queryString.getParam("failFast"),
31+
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
32+
hideDisabled: queryString.getParam("hideDisabled")
33+
};
34+
35+
var random = queryString.getParam("random");
36+
37+
if (random !== undefined && random !== "") {
38+
config.random = random;
39+
}
40+
41+
var seed = queryString.getParam("seed");
42+
if (seed) {
43+
config.seed = seed;
44+
}
45+
46+
/**
47+
* ## Reporters
48+
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
49+
*/
50+
var htmlReporter = new jasmine.HtmlReporter({
51+
env: env,
52+
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
53+
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
54+
getContainer: function() { return document.body; },
55+
createElement: function() { return document.createElement.apply(document, arguments); },
56+
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
57+
timer: new jasmine.Timer(),
58+
filterSpecs: filterSpecs
59+
});
60+
61+
/**
62+
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
63+
*/
64+
env.addReporter(jsApiReporter);
65+
env.addReporter(htmlReporter);
66+
67+
/**
68+
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
69+
*/
70+
var specFilter = new jasmine.HtmlSpecFilter({
71+
filterString: function() { return queryString.getParam("spec"); }
72+
});
73+
74+
config.specFilter = function(spec) {
75+
return specFilter.matches(spec.getFullName());
76+
};
77+
78+
env.configure(config);
79+
80+
/**
81+
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
82+
*/
83+
window.setTimeout = window.setTimeout;
84+
window.setInterval = window.setInterval;
85+
window.clearTimeout = window.clearTimeout;
86+
window.clearInterval = window.clearInterval;
87+
88+
/**
89+
* ## Execution
90+
*
91+
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
92+
*/
93+
var currentWindowOnload = window.onload;
94+
95+
window.onload = function() {
96+
if (currentWindowOnload) {
97+
currentWindowOnload();
98+
}
99+
htmlReporter.initialize();
100+
env.execute();
101+
};
102+
103+
/**
104+
* Helper function for readability above.
105+
*/
106+
function extend(destination, source) {
107+
for (var property in source) destination[property] = source[property];
108+
return destination;
109+
}
110+
111+
}());

0 commit comments

Comments
 (0)