"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "runtime/js/40_testing.js" between
deno-1.12.0.tar.gz and deno-1.12.1.tar.gz

About: Deno is is a simple, modern and secure runtime for JavaScript and TypeScript that uses the V8 JavaScript engine and is built in Rust.

40_testing.js  (deno-1.12.0):40_testing.js  (deno-1.12.1)
skipping to change at line 108 skipping to change at line 108
try { try {
await fn(); await fn();
} catch (err) { } catch (err) {
throw err; throw err;
} finally { } finally {
setExitHandler(null); setExitHandler(null);
} }
}; };
} }
function withPermissions(fn, permissions) {
function pledgePermissions(permissions) {
return core.opSync(
"op_pledge_test_permissions",
parsePermissions(permissions),
);
}
function restorePermissions(token) {
core.opSync("op_restore_test_permissions", token);
}
return async function applyPermissions() {
const token = pledgePermissions(permissions);
try {
await fn();
} finally {
restorePermissions(token);
}
};
}
const tests = []; const tests = [];
// Main test function provided by Deno, as you can see it merely // Main test function provided by Deno, as you can see it merely
// creates a new object with "name" and "fn" fields. // creates a new object with "name" and "fn" fields.
function test( function test(
t, t,
fn, fn,
) { ) {
let testDef; let testDef;
const defaults = { const defaults = {
skipping to change at line 156 skipping to change at line 179
} }
if (testDef.sanitizeResources) { if (testDef.sanitizeResources) {
testDef.fn = assertResources(testDef.fn); testDef.fn = assertResources(testDef.fn);
} }
if (testDef.sanitizeExit) { if (testDef.sanitizeExit) {
testDef.fn = assertExit(testDef.fn); testDef.fn = assertExit(testDef.fn);
} }
ArrayPrototypePush(tests, testDef); if (testDef.permissions) {
} testDef.fn = withPermissions(
testDef.fn,
parsePermissions(testDef.permissions),
);
}
function postTestMessage(kind, data) { ArrayPrototypePush(tests, testDef);
return core.opSync("op_post_test_message", { message: { kind, data } });
} }
function createTestFilter(filter) { function createTestFilter(filter) {
return (def) => { return (def) => {
if (filter) { if (filter) {
if ( if (
StringPrototypeStartsWith(filter, "/") && StringPrototypeStartsWith(filter, "/") &&
StringPrototypeEndsWith(filter, "/") StringPrototypeEndsWith(filter, "/")
) { ) {
const regex = new RegExp( const regex = new RegExp(
skipping to change at line 183 skipping to change at line 209
return RegExpPrototypeTest(regex, def.name); return RegExpPrototypeTest(regex, def.name);
} }
return StringPrototypeIncludes(def.name, filter); return StringPrototypeIncludes(def.name, filter);
} }
return true; return true;
}; };
} }
function pledgeTestPermissions(permissions) { async function runTest({ ignore, fn }) {
return core.opSync(
"op_pledge_test_permissions",
parsePermissions(permissions),
);
}
function restoreTestPermissions(token) {
core.opSync("op_restore_test_permissions", token);
}
async function runTest({ ignore, fn, permissions }) {
if (ignore) { if (ignore) {
return "ignored"; return "ignored";
} }
let token = null;
try { try {
if (permissions) {
token = pledgeTestPermissions(permissions);
}
await fn(); await fn();
return "ok"; return "ok";
} catch (error) { } catch (error) {
return { "failed": inspectArgs([error]) }; return { "failed": inspectArgs([error]) };
} finally {
if (token) {
restoreTestPermissions(token);
}
} }
} }
function getTestOrigin() {
return core.opSync("op_get_test_origin");
}
function dispatchTestEvent(event) {
return core.opSync("op_dispatch_test_event", event);
}
async function runTests({ async function runTests({
disableLog = false, disableLog = false,
filter = null, filter = null,
shuffle = null, shuffle = null,
} = {}) { } = {}) {
const origin = getTestOrigin();
const originalConsole = globalThis.console; const originalConsole = globalThis.console;
if (disableLog) { if (disableLog) {
globalThis.console = new Console(() => {}); globalThis.console = new Console(() => {});
} }
const only = ArrayPrototypeFilter(tests, (test) => test.only); const only = ArrayPrototypeFilter(tests, (test) => test.only);
const pending = ArrayPrototypeFilter( const filtered = ArrayPrototypeFilter(
(only.length > 0 ? only : tests), (only.length > 0 ? only : tests),
createTestFilter(filter), createTestFilter(filter),
); );
postTestMessage("plan", {
filtered: tests.length - pending.length, dispatchTestEvent({
pending: pending.length, plan: {
only: only.length > 0, origin,
total: filtered.length,
filteredOut: tests.length - filtered.length,
usedOnly: only.length > 0,
},
}); });
if (shuffle !== null) { if (shuffle !== null) {
// http://en.wikipedia.org/wiki/Linear_congruential_generator // http://en.wikipedia.org/wiki/Linear_congruential_generator
const nextInt = (function (state) { const nextInt = (function (state) {
const m = 0x80000000; const m = 0x80000000;
const a = 1103515245; const a = 1103515245;
const c = 12345; const c = 12345;
return function (max) { return function (max) {
return state = ((a * state + c) % m) % max; return state = ((a * state + c) % m) % max;
}; };
}(shuffle)); }(shuffle));
for (let i = pending.length - 1; i > 0; i--) { for (let i = filtered.length - 1; i > 0; i--) {
const j = nextInt(i); const j = nextInt(i);
[pending[i], pending[j]] = [pending[j], pending[i]]; [filtered[i], filtered[j]] = [filtered[j], filtered[i]];
} }
} }
for (const test of pending) { for (const test of filtered) {
const { const description = {
name, origin,
} = test; name: test.name,
};
const earlier = DateNow(); const earlier = DateNow();
postTestMessage("wait", { dispatchTestEvent({ wait: description });
name,
});
const result = await runTest(test); const result = await runTest(test);
const duration = DateNow() - earlier; const elapsed = DateNow() - earlier;
postTestMessage("result", { dispatchTestEvent({ result: [description, result, elapsed] });
name,
result,
duration,
});
} }
if (disableLog) { if (disableLog) {
globalThis.console = originalConsole; globalThis.console = originalConsole;
} }
} }
window.__bootstrap.internals = { window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {}, ...window.__bootstrap.internals ?? {},
runTests, runTests,
 End of changes. 18 change blocks. 
47 lines changed or deleted 59 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)