60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
// The Tests window's logic: node --test ide/ui/js/tests-model.test.mjs
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { worst, counts, sideBySide, phpTestMarks, duration, locations } from './tests-model.js';
|
|
|
|
test('a group shows the worst status of its tests', () => {
|
|
assert.equal(worst(['passed', 'skipped', 'failed', null]), 'failed');
|
|
assert.equal(worst(['passed', 'running']), 'running');
|
|
assert.equal(worst([null, undefined]), null);
|
|
assert.deepEqual(counts([{ status: 'passed', duration: 5 }, { status: 'error', duration: 1 }, { status: 'skipped' }]),
|
|
{ passed: 1, failed: 1, skipped: 1, running: 0, total: 3, ms: 6 });
|
|
});
|
|
|
|
test('expected and actual face each other line by line', () => {
|
|
const rows = sideBySide("Array (\n 'age' => 36\n 'name' => 'Ada'\n)", "Array (\n 'age' => 37\n 'name' => 'Ada'\n 'x' => 1\n)");
|
|
assert.deepEqual(rows.map((r) => r.kind), ['same', 'changed', 'same', 'added', 'same']);
|
|
assert.equal(rows[1].left, " 'age' => 36");
|
|
assert.equal(rows[1].right, " 'age' => 37");
|
|
assert.equal(rows[3].left, null);
|
|
});
|
|
|
|
test('the test classes and methods of a PHP file, with their lines', () => {
|
|
const text = `<?php
|
|
namespace App\\Tests;
|
|
|
|
use PHPUnit\\Framework\\Attributes\\Test;
|
|
|
|
final class CalcTest extends TestCase
|
|
{
|
|
public function testAdd(): void {}
|
|
|
|
#[Test]
|
|
#[DataProvider('rows')]
|
|
public function itSums(): void {}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function viaDoc(): void {}
|
|
|
|
public function helper(): void {}
|
|
|
|
public static function rows(): array { return []; }
|
|
}
|
|
|
|
abstract class BaseTest extends TestCase
|
|
{
|
|
public function testHidden(): void {}
|
|
}`;
|
|
assert.deepEqual(phpTestMarks(text).map((m) => [m.line, m.kind, m.id]), [
|
|
[6, 'class', 'App\\Tests\\CalcTest'], [8, 'method', 'App\\Tests\\CalcTest::testAdd'], [12, 'method', 'App\\Tests\\CalcTest::itSums'], [17, 'method', 'App\\Tests\\CalcTest::viaDoc'],
|
|
]);
|
|
});
|
|
|
|
test('durations and stack locations', () => {
|
|
assert.equal(duration(12), '12 ms');
|
|
assert.equal(duration(1400), '1.4 s');
|
|
assert.equal(duration(125000), '2 min 5 s');
|
|
assert.deepEqual(locations('at tests/X.php:12\n at TestContext (file:///w/a.test.mjs:5:36)').map((l) => [l.path, l.line]), [['tests/X.php', 12], ['/w/a.test.mjs', 5]]);
|
|
});
|