fix frontend tests broken with aiscript 1.0.0 (#16377)
* test: update test for aiscript 1.0: line info in error * test: update test for aiscript 1.0: keyword in object literal
This commit is contained in:
parent
785b85ee46
commit
103d5a4b44
|
|
@ -37,6 +37,17 @@ let $iMock = vi.hoisted<Partial<typeof import('@/i.js').$i> | null >(
|
||||||
() => null
|
() => null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function errorWithPos<T extends errors.AiScriptError>(
|
||||||
|
error: T,
|
||||||
|
line: number,
|
||||||
|
column: number,
|
||||||
|
): T {
|
||||||
|
const pos = { line, column };
|
||||||
|
error.pos = pos;
|
||||||
|
error.message = error.message + `\n at <root> (Line ${pos.line}, Column ${pos.column})`;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
vi.mock('@/i.js', () => {
|
vi.mock('@/i.js', () => {
|
||||||
return {
|
return {
|
||||||
get $i() {
|
get $i() {
|
||||||
|
|
@ -316,7 +327,7 @@ describe('AiScript common API', () => {
|
||||||
await expect(() => exe(`
|
await expect(() => exe(`
|
||||||
Mk:api('https://example.com/api/ping', {})
|
Mk:api('https://example.com/api/ping', {})
|
||||||
`)).rejects.toStrictEqual(
|
`)).rejects.toStrictEqual(
|
||||||
new errors.AiScriptRuntimeError('invalid endpoint'),
|
errorWithPos(new errors.AiScriptRuntimeError('invalid endpoint'), 2, 11),
|
||||||
);
|
);
|
||||||
expect(misskeyApiMock).not.toHaveBeenCalled();
|
expect(misskeyApiMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
@ -325,7 +336,7 @@ describe('AiScript common API', () => {
|
||||||
await expect(() => exe(`
|
await expect(() => exe(`
|
||||||
Mk:api('ping')
|
Mk:api('ping')
|
||||||
`)).rejects.toStrictEqual(
|
`)).rejects.toStrictEqual(
|
||||||
new errors.AiScriptRuntimeError('expected param'),
|
errorWithPos(new errors.AiScriptRuntimeError('expected param'), 2, 11),
|
||||||
);
|
);
|
||||||
expect(misskeyApiMock).not.toHaveBeenCalled();
|
expect(misskeyApiMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
@ -353,7 +364,7 @@ describe('AiScript common API', () => {
|
||||||
await expect(() => exe(`
|
await expect(() => exe(`
|
||||||
Mk:save('key')
|
Mk:save('key')
|
||||||
`)).rejects.toStrictEqual(
|
`)).rejects.toStrictEqual(
|
||||||
new errors.AiScriptRuntimeError('Expect anything, but got nothing.'),
|
errorWithPos(new errors.AiScriptRuntimeError('Expect anything, but got nothing.'), 2, 12),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,10 +316,11 @@ describe('AiScript UI API', () => {
|
||||||
|
|
||||||
describe('textInput', () => {
|
describe('textInput', () => {
|
||||||
test.concurrent('all options', async () => {
|
test.concurrent('all options', async () => {
|
||||||
|
// https://github.com/aiscript-dev/aiscript/pull/948
|
||||||
const { root, get, outputs } = await exe(`
|
const { root, get, outputs } = await exe(`
|
||||||
let text_input = Ui:C:textInput({
|
let text_input = Ui:C:textInput({
|
||||||
onInput: print
|
onInput: print
|
||||||
default: 'a'
|
"default": 'a'
|
||||||
label: 'b'
|
label: 'b'
|
||||||
caption: 'c'
|
caption: 'c'
|
||||||
}, 'id')
|
}, 'id')
|
||||||
|
|
@ -356,10 +357,11 @@ describe('AiScript UI API', () => {
|
||||||
|
|
||||||
describe('textarea', () => {
|
describe('textarea', () => {
|
||||||
test.concurrent('all options', async () => {
|
test.concurrent('all options', async () => {
|
||||||
|
// https://github.com/aiscript-dev/aiscript/pull/948
|
||||||
const { root, get, outputs } = await exe(`
|
const { root, get, outputs } = await exe(`
|
||||||
let textarea = Ui:C:textarea({
|
let textarea = Ui:C:textarea({
|
||||||
onInput: print
|
onInput: print
|
||||||
default: 'a'
|
"default": 'a'
|
||||||
label: 'b'
|
label: 'b'
|
||||||
caption: 'c'
|
caption: 'c'
|
||||||
}, 'id')
|
}, 'id')
|
||||||
|
|
@ -396,10 +398,11 @@ describe('AiScript UI API', () => {
|
||||||
|
|
||||||
describe('numberInput', () => {
|
describe('numberInput', () => {
|
||||||
test.concurrent('all options', async () => {
|
test.concurrent('all options', async () => {
|
||||||
|
// https://github.com/aiscript-dev/aiscript/pull/948
|
||||||
const { root, get, outputs } = await exe(`
|
const { root, get, outputs } = await exe(`
|
||||||
let number_input = Ui:C:numberInput({
|
let number_input = Ui:C:numberInput({
|
||||||
onInput: print
|
onInput: print
|
||||||
default: 1
|
"default": 1
|
||||||
label: 'a'
|
label: 'a'
|
||||||
caption: 'b'
|
caption: 'b'
|
||||||
}, 'id')
|
}, 'id')
|
||||||
|
|
@ -557,10 +560,11 @@ describe('AiScript UI API', () => {
|
||||||
|
|
||||||
describe('switch', () => {
|
describe('switch', () => {
|
||||||
test.concurrent('all options', async () => {
|
test.concurrent('all options', async () => {
|
||||||
|
// https://github.com/aiscript-dev/aiscript/pull/948
|
||||||
const { root, get, outputs } = await exe(`
|
const { root, get, outputs } = await exe(`
|
||||||
let switch = Ui:C:switch({
|
let switch = Ui:C:switch({
|
||||||
onChange: print
|
onChange: print
|
||||||
default: false
|
"default": false
|
||||||
label: 'a'
|
label: 'a'
|
||||||
caption: 'b'
|
caption: 'b'
|
||||||
}, 'id')
|
}, 'id')
|
||||||
|
|
@ -597,6 +601,7 @@ describe('AiScript UI API', () => {
|
||||||
|
|
||||||
describe('select', () => {
|
describe('select', () => {
|
||||||
test.concurrent('all options', async () => {
|
test.concurrent('all options', async () => {
|
||||||
|
// https://github.com/aiscript-dev/aiscript/pull/948
|
||||||
const { root, get, outputs } = await exe(`
|
const { root, get, outputs } = await exe(`
|
||||||
let select = Ui:C:select({
|
let select = Ui:C:select({
|
||||||
items: [
|
items: [
|
||||||
|
|
@ -604,7 +609,7 @@ describe('AiScript UI API', () => {
|
||||||
{ text: 'B', value: 'b' }
|
{ text: 'B', value: 'b' }
|
||||||
]
|
]
|
||||||
onChange: print
|
onChange: print
|
||||||
default: 'a'
|
"default": 'a'
|
||||||
label: 'c'
|
label: 'c'
|
||||||
caption: 'd'
|
caption: 'd'
|
||||||
}, 'id')
|
}, 'id')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue