40 lines
2.3 KiB
JavaScript
40 lines
2.3 KiB
JavaScript
'use strict';
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const vm = require('node:vm');
|
|
const roots = ['.', 'release/MAC_arm64_SpineViewer', 'release/WIN_x64_SpineViewer'];
|
|
for (const root of roots) {
|
|
const html = fs.readFileSync(path.join(root, 'viewer/spine.html'), 'utf8');
|
|
const script = html.match(/<script>([\s\S]*?)<\/script>/)[1];
|
|
new vm.Script(script);
|
|
const i18n = script.slice(script.indexOf('\tconst I18N_LANGUAGES'), script.indexOf('\tapplyStaticI18n();'));
|
|
const markers = script.slice(script.indexOf('\tfunction renderKeyframeMarkers('), script.indexOf('\tfunction seekTo('));
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'manifest.json'), 'utf8'));
|
|
for (const lang of manifest.languages) {
|
|
const table = JSON.parse(fs.readFileSync(path.join(root, '_locales', lang + '.json'), 'utf8'));
|
|
for (const match of html.matchAll(/(?:\bt\(['"]|data-i18n(?:-title|-aria-label)?=")([^'"]+)/g)) {
|
|
assert.equal(typeof match[1].split('.').reduce((obj, key) => obj && obj[key], table), 'string', `${root}/${lang}: ${match[1]}`);
|
|
}
|
|
const children = [];
|
|
const context = vm.createContext({
|
|
require, path, fs, __dirname: path.resolve(root, 'viewer'), lang, log() {},
|
|
document: { documentElement: {}, createElement: () => ({ style: {}, setAttribute(key, value) { this[key] = value; } }) },
|
|
keyframesEl: { innerHTML: '', appendChild: el => children.push(el) },
|
|
isStaticAnimation: false, duration: 2,
|
|
collectKeyframeTimes: () => [0, 1, 2, 3],
|
|
formatSeconds: value => `${value}s`, frameOf: value => value * 30
|
|
});
|
|
vm.runInContext(i18n + '\n' + markers + '\nrenderKeyframeMarkers({});', context);
|
|
assert.equal(children.length, 3);
|
|
assert.equal(children[1].style.left, '50%');
|
|
assert.equal(children[1].title, table.viewer.keyframeTitle.replace('{time}', '1s').replace('{frame}', '30'));
|
|
assert.equal(children[1]['aria-label'], children[1].title);
|
|
children.length = 0;
|
|
context.isStaticAnimation = true;
|
|
vm.runInContext('renderKeyframeMarkers({});', context);
|
|
assert.equal(children[0].title, table.viewer.staticPoseTitle);
|
|
}
|
|
}
|
|
console.log('PASS: source and both releases; eight languages; animated/static keyframe labels and translation keys');
|