Skip to content
Snippets Groups Projects
Verified Commit 8d576ec3 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: work on webtests

parent f9fa2270
No related branches found
No related tags found
No related merge requests found
...@@ -487,3 +487,5 @@ devenv.local.nix ...@@ -487,3 +487,5 @@ devenv.local.nix
.direnv .direnv
result result
# pupeeter screenshot of the test page
screenshot.png
\ No newline at end of file
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
- rt - rt
env: env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}" USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
desc: Run the tests desc: Run tests with node
cmds: cmds:
- ${script-run-tests}/bin/run-tests - ${script-run-tests}/bin/run-tests
...@@ -90,8 +90,9 @@ ...@@ -90,8 +90,9 @@
- rt - rt
env: env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}" USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
desc: Run the tests desc: Run the tests in the browser
cmds: cmds:
- ${script-update-web-test}/bin/update-web-test
- ${script-run-web-tests}/bin/run-web-tests - ${script-run-web-tests}/bin/run-web-tests
build-and-publish: build-and-publish:
......
...@@ -18,7 +18,8 @@ in ...@@ -18,7 +18,8 @@ in
echo_fail "Tests failed, check your JS!" echo_fail "Tests failed, check your JS!"
exit 1 exit 1
fi fi
exit 0
echo_ok "Tests passed!"
'' ''
...@@ -6,25 +6,6 @@ ...@@ -6,25 +6,6 @@
packageData = builtins.fromJSON (builtins.readFile ../../package.json); packageData = builtins.fromJSON (builtins.readFile ../../package.json);
version = packageData.version; version = packageData.version;
lib = pkgs.lib; lib = pkgs.lib;
# root = ../..;
# gitignore = ../../.gitignore;
# source = ../../source;
# test = ../../test;
#
# releasedPackageJson = {
# description = packageData.description;
# name = packageData.name;
# version = version;
# dependencies = packageData.dependencies;
# keywords = packageData.keywords;
# license = packageData.license;
# repository = packageData.repository;
# author = packageData.author;
# homepage = packageData.homepage;
# type = "module";
# main = "source/monster.mjs";
# module = "source/monster.mjs";
# };
in in
pkgs.writeShellScriptBin "update-web-test" '' pkgs.writeShellScriptBin "update-web-test" ''
source ${commonScript} source ${commonScript}
...@@ -33,7 +14,7 @@ in ...@@ -33,7 +14,7 @@ in
echo_hint "This script will check the code for formatting and linting issues" echo_hint "This script will check the code for formatting and linting issues"
echo_hint "The command is executed in the current working directory and not in a nix derivation." echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir cd_working_dir
set -x
echo_step "Running prettier" echo_step "Running prettier"
PROJECT_ROOT="$(pwd)" PROJECT_ROOT="$(pwd)"
......
...@@ -4,10 +4,6 @@ import {initWebSocket} from "../../../../util/websocket.mjs"; ...@@ -4,10 +4,6 @@ import {initWebSocket} from "../../../../util/websocket.mjs";
const testUrl = "wss://ws.postman-echo.com/raw" const testUrl = "wss://ws.postman-echo.com/raw"
// const g = getGlobal();
// g['WebSocket'] = WS;
describe('Websocket', function () { describe('Websocket', function () {
let ds = undefined let ds = undefined
...@@ -25,7 +21,7 @@ describe('Websocket', function () { ...@@ -25,7 +21,7 @@ describe('Websocket', function () {
ds.close() ds.close()
} }
// workaround: without this, the node test will hang // workaround: without this, the node test will not exit
for (const sym of Object.getOwnPropertySymbols(ds)) { for (const sym of Object.getOwnPropertySymbols(ds)) {
if (sym.toString() === 'Symbol(connection)') { if (sym.toString() === 'Symbol(connection)') {
const connection = ds[sym] const connection = ds[sym]
...@@ -49,10 +45,8 @@ describe('Websocket', function () { ...@@ -49,10 +45,8 @@ describe('Websocket', function () {
ds = new WebConnect(testUrl) ds = new WebConnect(testUrl)
const clone = ds.getClone() const clone = ds.getClone()
expect(clone).to.be.an.instanceof(WebConnect) expect(clone).to.be.an.instanceof(WebConnect)
}) })
it('should transform data', function (done) { it('should transform data', function (done) {
...@@ -149,13 +143,17 @@ describe('Websocket', function () { ...@@ -149,13 +143,17 @@ describe('Websocket', function () {
}) })
it('should send message', function (done) { it('should send a message', function (done) {
this.timeout(10000)
ds = new WebConnect({ ds = new WebConnect({
url: testUrl, url: testUrl,
reconnect: { reconnect: {
enabled: false enabled: false
} }
}); });
ds.connect().then(() => { ds.connect().then(() => {
ds.set({ ds.set({
envelop: { envelop: {
...@@ -189,6 +187,6 @@ describe('Websocket', function () { ...@@ -189,6 +187,6 @@ describe('Websocket', function () {
}) })
}).timeout(10000); });
}); });
...@@ -25,13 +25,49 @@ describe('Transformer', function () { ...@@ -25,13 +25,49 @@ describe('Transformer', function () {
}); });
describe('Transformer.run() localize commands', function () {
const isNode = typeof global === 'object' && '[object global]' === global.toString.call(global);
[
['datetimeformat', "2023-02-04 08:02:01", "Feb 4, 2023, 08:02:01", "4 Feb 2023, 08:02:01"],
['datetimeformat:long:short', "2023-02-04 08:02:01", "February 4, 2023 at 08:02", "4 February 2023 at 08:02"],
['datetimeformat:short:short', "2023-02-04 08:02:01", "2/4/23, 08:02", "04/02/2023, 08:02"],
['currency', "EUR0", "€0.00", "€0.00"],
['currency:1:2', "EUR14.25", "€14.2", "€14.2"],
['currency', "EUR14.25", "€14.25", "€14.25"],
['datetime', "2023-02-14 14:12:10", "2/14/2023, 14:12:10","14/02/2023, 14:12:10"],
['datetime', "2023-02-14 08:02:01", "2/14/2023, 08:02:01","14/02/2023, 08:02:01"],
['date', "2023-02-14", "02/14/2023","14/02/2023"],
].forEach(function (data) {
// https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/124
let a = data.shift() // command
let b = data.shift() // value
let c = data.shift() // expected result node
let d = data.shift() // expected result browser
const expected = isNode ? c : d
it('Transformer.run(' + JSON.stringify(a) + ').run(' + JSON.stringify(b) + ') should return ' + JSON.stringify(expected), function () {
let t = new Transformer(a);
const r = t.run(b);
expect(expected).to.be.eql(r, "Transformer.run(" + JSON.stringify(a) + ").run(" + JSON.stringify(b) + ") should return " + JSON.stringify(c));
});
});
});
describe('Transformer.run()', function () { describe('Transformer.run()', function () {
[ [
['datetimeformat', "2023-02-04 08:02:01", "Feb 4, 2023, 08:02:01"],
['datetimeformat:long:short', "2023-02-04 08:02:01","February 4, 2023 at 08:02"],
['datetimeformat:short:short', "2023-02-04 08:02:01", "2/4/23, 08:02"],
['equals:a', "a", true], ['equals:a', "a", true],
['equals:a', "b", false], ['equals:a', "b", false],
['equals:3', 3, true], ['equals:3', 3, true],
...@@ -51,11 +87,6 @@ describe('Transformer', function () { ...@@ -51,11 +87,6 @@ describe('Transformer', function () {
['equals:null', null, true], ['equals:null', null, true],
['equals:null', 3, false], ['equals:null', 3, false],
['equals:3', 6, false], ['equals:3', 6, false],
['currency', "EUR0", "€0.00"], // 0,00 €
// ['currency:1:2', "EUR14.25", "14,2 €"], nodejs and browser have different results (https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/124)
['currency', "EUR14.25", "€14.25"],
['datetime', "2023-02-14 14:12:10", "2/14/2023, 14:12:10"],
['datetime', "2023-02-14 08:02:01", "2/14/2023, 08:02:01"],
['has-entries', {}, false], ['has-entries', {}, false],
['has-entries', {a: 4}, true], ['has-entries', {a: 4}, true],
['has-entries', [], false], ['has-entries', [], false],
...@@ -90,7 +121,6 @@ describe('Transformer', function () { ...@@ -90,7 +121,6 @@ describe('Transformer', function () {
['not', true, false], ['not', true, false],
['not', false, true], ['not', false, true],
['map:a=4:b=5:c=6', "a", "4"], ['map:a=4:b=5:c=6', "a", "4"],
['date', "2023-02-14", "02/14/2023"],
['year', "2023-02-14", 2023], ['year', "2023-02-14", 2023],
['month', "2023-02-14", 2], ['month', "2023-02-14", 2],
['day', "2023-02-14", 14], ['day', "2023-02-14", 14],
...@@ -201,26 +231,6 @@ describe('Transformer', function () { ...@@ -201,26 +231,6 @@ describe('Transformer', function () {
let c = data.shift() let c = data.shift()
it('Transformer.run(' + JSON.stringify(a) + ').run(' + JSON.stringify(b) + ') should return ' + JSON.stringify(c), function () { it('Transformer.run(' + JSON.stringify(a) + ').run(' + JSON.stringify(b) + ') should return ' + JSON.stringify(c), function () {
// const [major, minor, patch] = process.versions.node.split('.').map(Number)
// console.log(major, minor, patch,'!!!!!!!!!!!')
//
// const args=a.split(':');
// args.shift();
//
// let date = new Date(b);
// const options = {
// dateStyle: args.shift() || "medium",
// timeStyle: args.shift() || "medium",
// };
//
// console.log(options,'options')
//
// // const locale = getLocaleOfDocument();
// //const intl= new Intl.DateTimeFormat("en", options).format(new Date("2023-02-04 08:02:01"));
// //console.log(intl,'intl')
let t = new Transformer(a); let t = new Transformer(a);
t.setCallback('testcallback', function (a, b, c, d) { t.setCallback('testcallback', function (a, b, c, d) {
......
...@@ -125,7 +125,6 @@ describe('DOM', function () { ...@@ -125,7 +125,6 @@ describe('DOM', function () {
expect(e).to.be.null; expect(e).to.be.null;
} }
console.log(typeof d,"ssss");
expect(typeof d).is.equal('object'); expect(typeof d).is.equal('object');
}); });
......
...@@ -43,8 +43,6 @@ describe('DOM', function () { ...@@ -43,8 +43,6 @@ describe('DOM', function () {
assignUpdaterToElement = function (elements, object) { assignUpdaterToElement = function (elements, object) {
return addObjectWithUpdaterToElement.call(this, elements, updaterSymbolSymbol, object); return addObjectWithUpdaterToElement.call(this, elements, updaterSymbolSymbol, object);
} }
document = getDocument(); document = getDocument();
done() done()
...@@ -139,7 +137,7 @@ describe('DOM', function () { ...@@ -139,7 +137,7 @@ describe('DOM', function () {
expect(JSON.stringify(ap.getRealSubject())).to.equal('{"a":3}'); expect(JSON.stringify(ap.getRealSubject())).to.equal('{"a":3}');
expect(JSON.stringify(bp.getRealSubject())).to.equal('{"b":4}'); expect(JSON.stringify(bp.getRealSubject())).to.equal('{"b":4}');
done() done()
}, 10) }, 50)
}) })
......
...@@ -72,7 +72,13 @@ function initJSDOM(options) { ...@@ -72,7 +72,13 @@ function initJSDOM(options) {
'ShadowRoot', 'ShadowRoot',
'XMLSerializer', 'XMLSerializer',
].forEach(key => { ].forEach(key => {
try {
g[key] = window[key] g[key] = window[key]
} catch(e) {
console.error("Error setting key", key, e);
}
}); });
import("dom-storage").then(({default: Storage}) => { import("dom-storage").then(({default: Storage}) => {
......
...@@ -2,8 +2,9 @@ import {getGlobal} from "../../source/types/global.mjs"; ...@@ -2,8 +2,9 @@ import {getGlobal} from "../../source/types/global.mjs";
function initWebSocket() { function initWebSocket() {
const title = process.title; // const isBrowser = typeof window === 'object' && '[object Window]' === window.toString.call(window)
const isNode = typeof process !== 'undefined' && title.includes('node'); const isNode = typeof global === 'object' && '[object global]' === global.toString.call(global)
if (!isNode) { if (!isNode) {
return Promise.resolve(); return Promise.resolve();
......
...@@ -84,7 +84,6 @@ if (!config.browser) { ...@@ -84,7 +84,6 @@ if (!config.browser) {
console.log('Tests failed:', failures); console.log('Tests failed:', failures);
console.log('Duration:', duration); console.log('Duration:', duration);
// rm -rf screenshot.png (javascript)
if (existsSync('screenshot.png')) { if (existsSync('screenshot.png')) {
unlinkSync('screenshot.png'); unlinkSync('screenshot.png');
} }
...@@ -97,7 +96,7 @@ if (!config.browser) { ...@@ -97,7 +96,7 @@ if (!config.browser) {
await page.evaluate(() => { await page.evaluate(() => {
document.querySelectorAll('.test.fail').forEach((node) => { document.querySelectorAll('.test.fail').forEach((node) => {
console.log(node.textContent); console.error(node.textContent);
}); });
}); });
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<body> <body>
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;"> <div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
<h1 style='margin-bottom: 0.1em;'>Monster 3.65.0</h1> <h1 style='margin-bottom: 0.1em;'>Monster 3.65.0</h1>
<div id="lastupdate" style='font-size:0.7em'>last update Mi 15. Mai 23:43:52 CEST 2024</div> <div id="lastupdate" style='font-size:0.7em'>last update Do 16. Mai 12:17:05 CEST 2024</div>
</div> </div>
<div id="mocha-errors" <div id="mocha-errors"
style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div> style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment