mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
## Summary Moves `static/assert.ts` and `static/rison.ts` to `shared/` directory to make them available to both frontend and backend code without browser dependencies. Updates all import paths across the codebase (~47 files). ## Motivation This refactoring eliminates browser dependencies in these utilities, allowing them to be imported by Node.js contexts (like Cypress test files) without causing module load failures. This is a prerequisite for upcoming Cypress test improvements. ## Changes - Move `static/assert.ts` → `shared/assert.ts` - Move `static/rison.ts` → `shared/rison.ts` - Update `biome.json` to allow `hasOwnProperty` in `shared/` directory - Update all imports across `static/`, `lib/`, and `test/` directories (47 files changed) ## Benefits - No functional changes, purely a code reorganization - Makes these utilities accessible to both frontend and backend without circular dependencies - Enables future Cypress improvements that require these utilities in Node.js context - All tests pass ✓ (699 tests) ## Test Plan - [x] TypeScript compilation passes - [x] Linting passes - [x] All unit tests pass (699 tests) - [x] Pre-commit hooks pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import {describe, expect, it} from 'vitest';
|
|
|
|
import * as rison from '../shared/rison.js';
|
|
|
|
// Copied from https://github.com/Nanonid/rison/blob/master/python/rison/tests.py
|
|
const py_testcases = {
|
|
'(a:0,b:1)': {a: 0, b: 1},
|
|
"(a:0,b:foo,c:'23skidoo')": {a: 0, c: '23skidoo', b: 'foo'},
|
|
'!t': true,
|
|
'!f': false,
|
|
'!n': null,
|
|
"''": '',
|
|
0: 0,
|
|
1.5: 1.5,
|
|
'-3': -3,
|
|
'1e30': 1e30,
|
|
'1e-30': 1.0000000000000001e-30,
|
|
'G.': 'G.',
|
|
a: 'a',
|
|
"'0a'": '0a',
|
|
"'abc def'": 'abc def',
|
|
'()': {},
|
|
'(a:0)': {a: 0},
|
|
'(id:!n,type:/common/document)': {type: '/common/document', id: null},
|
|
'!()': [],
|
|
"!(!t,!f,!n,'')": [true, false, null, ''],
|
|
"'-h'": '-h',
|
|
'a-z': 'a-z',
|
|
"'wow!!'": 'wow!',
|
|
'domain.com': 'domain.com',
|
|
"'user@domain.com'": 'user@domain.com',
|
|
"'US $10'": 'US $10',
|
|
"'can!'t'": "can't",
|
|
};
|
|
|
|
const encode_testcases = {
|
|
"can't": "'can!'t'",
|
|
'"can\'t"': "'\"can!'t\"'",
|
|
"'can't'": "'!'can!'t!''",
|
|
};
|
|
|
|
describe('Rison test cases', () => {
|
|
for (const [r, obj] of Object.entries(py_testcases)) {
|
|
it(`Should decode "${r}"`, () => {
|
|
// hack to get around "TypeError: Cannot read properties of null (reading 'should')"
|
|
expect(rison.decode(r)).toEqual(obj);
|
|
});
|
|
it(`Should encode ${JSON.stringify(obj)}`, () => {
|
|
expect(rison.encode(obj)).toEqual(r);
|
|
});
|
|
}
|
|
for (const [obj, r] of Object.entries(encode_testcases)) {
|
|
it(`Should encode ${JSON.stringify(obj)}`, () => {
|
|
expect(rison.encode(obj)).toEqual(r);
|
|
});
|
|
}
|
|
});
|