|
| 1 | +import { describe, it } from 'node:test' |
| 2 | +import * as nodeTest from 'node:test' |
| 3 | + |
| 4 | +const skip = !nodeTest.snapshot // Node.js 20.x and 22.12 (22.13 has it) |
| 5 | +const wrongSerialization = process.env.EXODUS_TEST_PLATFORM === 'xs' // https://github.com/Moddable-OpenSource/moddable/issues/1564 |
| 6 | + |
| 7 | +it('simple', { skip: skip || wrongSerialization }, (t) => { |
| 8 | + t.assert.snapshot(10) |
| 9 | + t.assert.snapshot(null) |
| 10 | + t.assert.snapshot() |
| 11 | + t.assert.snapshot([]) |
| 12 | + t.assert.snapshot(/xx/) |
| 13 | + t.assert.snapshot(Infinity) |
| 14 | + t.assert.snapshot(false) |
| 15 | + t.assert.snapshot(true) |
| 16 | + t.assert.snapshot({}) |
| 17 | +}) |
| 18 | + |
| 19 | +it('complex', { skip: skip || wrongSerialization }, (t) => { |
| 20 | + t.assert.snapshot([10]) |
| 21 | + t.assert.snapshot([{ a: 10 }]) |
| 22 | + t.assert.snapshot({ a: 10 }) |
| 23 | + t.assert.snapshot({ a: 10, b: 20 }) |
| 24 | + t.assert.snapshot(Buffer.from('')) |
| 25 | +}) |
| 26 | + |
| 27 | +// repeat test name |
| 28 | +it('simple', { skip: skip || wrongSerialization }, (t) => { |
| 29 | + t.assert.snapshot(/hello/) |
| 30 | + t.assert.snapshot(true) |
| 31 | + t.assert.snapshot(NaN) |
| 32 | + t.assert.snapshot({}) |
| 33 | + t.assert.snapshot(42) |
| 34 | + t.assert.snapshot([]) |
| 35 | + t.assert.snapshot(-Infinity) |
| 36 | +}) |
| 37 | + |
| 38 | +it('mixed', { skip: skip || wrongSerialization }, (t) => { |
| 39 | + t.assert.snapshot(true) |
| 40 | + t.assert.snapshot([1, 2, 3]) |
| 41 | + t.assert.snapshot({ foo: 'bar' }) |
| 42 | + t.assert.snapshot(43) |
| 43 | + t.assert.snapshot({}) |
| 44 | + t.assert.snapshot([]) |
| 45 | +}) |
| 46 | + |
| 47 | +// repeat test name |
| 48 | +it('mixed', { skip: skip || wrongSerialization }, (t) => { |
| 49 | + t.assert.snapshot([5, 4, 3]) |
| 50 | + t.assert.snapshot([]) |
| 51 | + t.assert.snapshot(false) |
| 52 | + t.assert.snapshot(41) |
| 53 | + t.assert.snapshot({ bar: 'buz' }) |
| 54 | + t.assert.snapshot({}) |
| 55 | +}) |
| 56 | + |
| 57 | +it('escape', { skip }, (t) => { |
| 58 | + t.assert.snapshot('\\') |
| 59 | + t.assert.snapshot('${') |
| 60 | + t.assert.snapshot('$$\\${') |
| 61 | +}) |
| 62 | + |
| 63 | +const TEST_ONE = { a: 20, d: Buffer.from('foo'), b: [1, 2, 'bar', 5], e: { foo: 'bar' } } |
| 64 | +// eslint-disable-next-line no-sparse-arrays |
| 65 | +const TEST_TWO = { ['__proto__']: [], b: [1, 2, , , 5], e: { foo: 'bar' }, f: -Infinity } |
| 66 | +const TEST_THREE = [new Error('?!'), new TypeError('bar'), new Uint16Array([4, 2, 65_123]), null] |
| 67 | + |
| 68 | +// Test names repeat on a purpose! |
| 69 | + |
| 70 | +it('test A', { skip }, (t) => { |
| 71 | + t.assert.snapshot(TEST_ONE) |
| 72 | +}) |
| 73 | + |
| 74 | +it('test B', { skip: skip || wrongSerialization }, (t) => { |
| 75 | + t.assert.snapshot(TEST_TWO) |
| 76 | +}) |
| 77 | + |
| 78 | +it('test B', { skip: skip || wrongSerialization }, (t) => { |
| 79 | + t.assert.snapshot(TEST_THREE) |
| 80 | +}) |
| 81 | + |
| 82 | +// Repeat name |
| 83 | +it('test B', { skip: skip || wrongSerialization }, (t) => { |
| 84 | + t.assert.snapshot({ x: 1337 }) |
| 85 | +}) |
| 86 | + |
| 87 | +describe('nested test', { skip }, () => { |
| 88 | + it('test A', { skip: wrongSerialization }, (t) => { |
| 89 | + t.assert.snapshot(TEST_TWO) |
| 90 | + }) |
| 91 | + |
| 92 | + it('test A', { skip: wrongSerialization }, (t) => { |
| 93 | + t.assert.snapshot(TEST_THREE) |
| 94 | + }) |
| 95 | + |
| 96 | + it('nested test one', (t) => { |
| 97 | + t.assert.snapshot(TEST_ONE) |
| 98 | + }) |
| 99 | +}) |
| 100 | + |
| 101 | +describe('weird names', { skip }, () => { |
| 102 | + const ascii = Array.from({ length: 128 }) |
| 103 | + .fill() |
| 104 | + .map((a, i) => i) |
| 105 | + .slice(0x20) |
| 106 | + .map((i) => String.fromCodePoint(i)) |
| 107 | + .join('') |
| 108 | + for (const key of [ |
| 109 | + '\n', |
| 110 | + '{}', |
| 111 | + '$', |
| 112 | + '`', |
| 113 | + '>', |
| 114 | + '` ` `', |
| 115 | + '` `\n `', |
| 116 | + '\\', |
| 117 | + '\\\n`\n\\``', |
| 118 | + '${', |
| 119 | + ascii, |
| 120 | + ]) { |
| 121 | + it(key, (t) => { |
| 122 | + t.assert.snapshot(key) |
| 123 | + }) |
| 124 | + } |
| 125 | + |
| 126 | + it('multi\nline', { skip }, (t) => { |
| 127 | + t.assert.snapshot(0) |
| 128 | + }) |
| 129 | + |
| 130 | + it('with `', { skip }, (t) => { |
| 131 | + t.assert.snapshot(42) |
| 132 | + }) |
| 133 | +}) |
| 134 | + |
| 135 | +describe('', { skip }, () => { |
| 136 | + it('', (t) => { |
| 137 | + t.assert.snapshot('empty names test') |
| 138 | + t.assert.snapshot(t.fullName) |
| 139 | + t.assert.snapshot(t.name) |
| 140 | + }) |
| 141 | + |
| 142 | + it((t) => { |
| 143 | + t.assert.snapshot('no name test') |
| 144 | + t.assert.snapshot(t.fullName) |
| 145 | + t.assert.snapshot(t.name) |
| 146 | + }) |
| 147 | + |
| 148 | + // non-string names |
| 149 | + for (const name of [false, true, 0, 1, null, undefined, {}, ['arr'], 'str']) { |
| 150 | + it(name, (t) => { |
| 151 | + t.assert.snapshot(t.fullName) |
| 152 | + t.assert.snapshot(t.name) |
| 153 | + }) |
| 154 | + } |
| 155 | +}) |
0 commit comments