Added code for browser tests using ChromeDriver.
Added a test for kfx. More tests coming soon. Fixes #21
This commit is contained in:
+7
-1
@@ -129,6 +129,12 @@ gulp.task("test-minified", ["libjass.min.js"], function (callback) {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task("test-browser", ["libjass.min.js"], function (callback) {
|
||||
npm.load(function () {
|
||||
npm.commands["run-script"](["test-browser"], callback);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task("test", ["test-lib", "test-minified"]);
|
||||
|
||||
gulp.task("demo", ["libjass.js"], function () {
|
||||
@@ -143,7 +149,7 @@ gulp.task("doc", ["libjass.js"], function () {
|
||||
.pipe(gulp.dest("../libjass-gh-pages/"));
|
||||
});
|
||||
|
||||
gulp.task("dist", ["clean", "default", "test", "demo", "doc"], function () {
|
||||
gulp.task("dist", ["clean", "default", "test", "test-browser", "demo", "doc"], function () {
|
||||
var inputFiles = [
|
||||
"./README.md", "./CHANGELOG.md", "./LICENSE",
|
||||
"./lib/libjass.js", "./lib/libjass.js.map",
|
||||
|
||||
+3
-1
@@ -19,12 +19,14 @@
|
||||
"prepublish": "gulp clean default",
|
||||
"test": "gulp test",
|
||||
"test-lib": "intern-client config=./tests/intern reporters=pretty",
|
||||
"test-minified": "intern-client config=./tests/intern reporters=pretty minified=true"
|
||||
"test-minified": "intern-client config=./tests/intern reporters=pretty minified=true",
|
||||
"test-browser": "intern-runner config=./tests/intern"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "3.x",
|
||||
"intern": "2.x",
|
||||
"npm": "2.x",
|
||||
"pngjs": "0.4.0",
|
||||
"typescript": "1.5.0-alpha",
|
||||
"uglify-js": "2.x >=2.4.16",
|
||||
"vinyl": "latest"
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,18 @@
|
||||
[Script Info]
|
||||
; Script generated by Aegisub 3.2.2
|
||||
; http://www.aegisub.org/
|
||||
Title: Default Aegisub file
|
||||
ScriptType: v4.00+
|
||||
WrapStyle: 0
|
||||
ScaledBorderAndShadow: yes
|
||||
YCbCr Matrix: None
|
||||
PlayResX: 256
|
||||
PlayResY: 144
|
||||
|
||||
[V4+ Styles]
|
||||
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
|
||||
Style: Default,Arial,36,&H00FFFFFF,&H000000FF,&H00000000,&H96000000,0,0,0,0,100,100,0,0,1,2,1.2,2,15,15,15,1
|
||||
|
||||
[Events]
|
||||
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
||||
Dialogue: 0,0:00:01.00,0:00:07.00,Default,,0,0,0,,{\k100}{\k200}a{\k100}bc{\k200}d
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* libjass
|
||||
*
|
||||
* https://github.com/Arnavion/libjass
|
||||
*
|
||||
* Copyright 2013 Arnav Singh
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
define(["intern!tdd", "require", "tests/support/test-page"], function (tdd, require, TestPage) {
|
||||
tdd.suite("WebDriver", function () {
|
||||
tdd.test("Basic", function () {
|
||||
var testPage = new TestPage(this.remote, require.toUrl("tests/support/browser-test-page.html"), "/tests/functional/kfx/kfx.ass", 256, 144);
|
||||
return testPage
|
||||
.prepare()
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(1.5, require.toUrl("./kfx-1.png")); })
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(2.5, require.toUrl("./kfx-2.png")); })
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(3.5, require.toUrl("./kfx-3.png")); })
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(4.5, require.toUrl("./kfx-4.png")); })
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(5.5, require.toUrl("./kfx-5.png")); })
|
||||
.then(function (testPage) { return testPage.seekAndCompareScreenshot(6.5, require.toUrl("./kfx-6.png")); });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -28,7 +28,14 @@ define(["intern"], function (intern) {
|
||||
"tests/unit/tags",
|
||||
"tests/unit/webworker"
|
||||
],
|
||||
functionalSuites: [
|
||||
"tests/functional/kfx/kfx"
|
||||
],
|
||||
excludeInstrumentation: /^(?:tests|node_modules)[/\\]/,
|
||||
tunnel: "NullTunnel",
|
||||
environments: [{
|
||||
browserName: "chrome",
|
||||
}],
|
||||
};
|
||||
|
||||
if (intern.args.minified === "true") {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* libjass
|
||||
*
|
||||
* https://github.com/Arnavion/libjass
|
||||
*
|
||||
* Copyright 2013 Arnav Singh
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>>2012 >Streaman Animu</title>
|
||||
<link rel="stylesheet" href="../../lib/libjass.css" />
|
||||
<link rel="stylesheet" href="browser-test-page.css" />
|
||||
<script src="../../lib/libjass.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="libjass-wrapper" />
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* libjass
|
||||
*
|
||||
* https://github.com/Arnavion/libjass
|
||||
*
|
||||
* Copyright 2013 Arnav Singh
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
define([
|
||||
"intern/dojo/node!fs",
|
||||
"intern/dojo/node!path",
|
||||
"intern/dojo/node!pngjs",
|
||||
"intern/chai!assert",
|
||||
"intern/dojo/node!intern/node_modules/leadfoot/helpers/pollUntil",
|
||||
"lib/libjass"
|
||||
], function (fs, path, pngjs, assert, pollUntil, libjass) {
|
||||
function TestPage(remote, pageUrl, assUrl, targetWidth, targetHeight) {
|
||||
this._remote = remote;
|
||||
this._pageUrl = pageUrl;
|
||||
this._assUrl = assUrl;
|
||||
this._targetWidth = targetWidth;
|
||||
this._targetHeight = targetHeight;
|
||||
}
|
||||
|
||||
TestPage.prototype.prepare = function () {
|
||||
var _this = this;
|
||||
|
||||
this._remote.session.setExecuteAsyncTimeout(10000);
|
||||
|
||||
return this._remote
|
||||
.setWindowSize(1280, 720)
|
||||
.get(this._pageUrl)
|
||||
.then(pollUntil('return (document.readyState === "complete") ? true : null;'), 100)
|
||||
.executeAsync(function (assUrl, callback) {
|
||||
window.clock = new libjass.renderers.ManualClock();
|
||||
var libjassSubsWrapper = document.querySelector(".libjass-wrapper");
|
||||
|
||||
libjass.ASS.fromUrl(assUrl).then(function (ass) {
|
||||
libjassSubsWrapper.style.width = ass.properties.resolutionX + "px";
|
||||
libjassSubsWrapper.style.height = ass.properties.resolutionY + "px";
|
||||
|
||||
var renderer = new libjass.renderers.WebRenderer(ass, clock, libjassSubsWrapper);
|
||||
renderer.addEventListener("ready", function () {
|
||||
renderer.resize(ass.properties.resolutionX, ass.properties.resolutionY);
|
||||
clock.pause();
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}, [this._assUrl])
|
||||
.then(function () { return _this; });
|
||||
};
|
||||
|
||||
TestPage.prototype.seekAndCompareScreenshot = function (time, filename) {
|
||||
var _this = this;
|
||||
|
||||
return this._remote
|
||||
.execute(function (time) { clock.seek(time); }, [time])
|
||||
.takeScreenshot()
|
||||
.then(function (buffer) {
|
||||
return new libjass.Promise(function (resolve, reject) {
|
||||
new pngjs.PNG().parse(buffer, function (error, input) {
|
||||
if (error !== null) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
var output = new pngjs.PNG({ width: _this._targetWidth, height: _this._targetHeight });
|
||||
input.bitblt(output, 0, 0, _this._targetWidth, _this._targetHeight, 0, 0);
|
||||
resolve(output);
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(function (screenshot) {
|
||||
return new libjass.Promise(function (resolve, reject) {
|
||||
var baselineBuffer = fs.readFileSync(filename);
|
||||
new pngjs.PNG().parse(baselineBuffer, function (error, baseline) {
|
||||
if (error !== null) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
assert.equal(0, screenshot.data.compare(baseline.data), filename + " does not match!");
|
||||
resolve();
|
||||
}
|
||||
catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}).catch(function (err) {
|
||||
return new libjass.Promise(function (resolve, reject) {
|
||||
var newFilename = filename.substr(0, filename.length - path.extname(filename).length) + "-new" + path.extname(filename);
|
||||
screenshot.pack().pipe(fs.createWriteStream(newFilename)).once("error", reject).on("finish", function () { reject(err); });
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(function () { return _this; });
|
||||
};
|
||||
|
||||
return TestPage;
|
||||
});
|
||||
Reference in New Issue
Block a user