Skip to content

Commit

Permalink
test: update failing tests expected output with heap value
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino committed Jun 24, 2024
1 parent 82ae8df commit a03e20e
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/core/test/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,56 @@ ParseError @slangroom/core@${packageJson.version}: at 2:74-84
const err = await t.throwsAsync(fn);
t.is(err?.message, expected);
});

test('Slangroom error are shown with context', async (t) => {
const plugin = new Plugin();
plugin.new('connect', ['param'], 'do some action', (_) => _.fail(new Error("Something went horribly wrong")));

const slang = new Slangroom(plugin);
const fn = slang.execute(`Rule unknown ignore
Given I connect to 'url' and send param 'param' and do some action and output into 'res'
Given I have a 'string' named 'res'
Then print data`,
{
data: {
url: 'https://example.com',
param: {
foo: 'bar'
}
},
keys: {
something: 'else'
}
});

const expected = `${lineNoColor('0 | ')}Rule unknown ignore
${lineNoColor('1 | ')}${sentenceHighlight(` ${textHighlight(`Given I connect to 'url' and send param 'param' and do some action and output into 'res'`)}`)}
${errorColor('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')}
${lineNoColor('2 | ')} Given I have a 'string' named 'res'
${lineNoColor('3 | ')} Then print data
Error colors:
- ${errorColor('error')}
- ${suggestedColor('suggested words')}
- ${missingColor('missing words')}
- ${extraColor('extra words')}
Error: Something went horribly wrong
Heap:
{
"data": {
"url": "https://example.com",
"param": {
"foo": "bar"
}
},
"keys": {
"something": "else"
}
}
`;

const err = await t.throwsAsync(fn);
t.is(err?.message, expected, err?.message);
});
36 changes: 36 additions & 0 deletions pkg/db/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ Error colors:
Slangroom @slangroom/db@${packageJson.version} Error: [DATABASE]
Returned null for id "30" in table "firstTable" in db "sqlite://./test/db1.db".
Heap:
{
"data": {
"n": 30,
"var_name": "obj_1",
"obj_1": "pippo",
"myDb1": "sqlite://./test/db1.db",
"myDb2": "sqlite://./test/db2.db",
"myTable": "firstTable",
"myCache": "firstCache",
"myOtherZenroomStringDictionary": {
"data": {
"data1": "9WgBlK+Kcq3AKpmhituXQe4UPkzH3zpZiQa4Szm1Q40=",
"data2": "BCEo8MgRiSxtLfxE4UEDVnbdZ21h+xc+egLIRk3VTagpJxlBfu9MjqXGUi2N7tIewpcDrr5V7Z2cmMcNsbKWSGQ="
}
}
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -265,5 +285,21 @@ Error colors:
- extra words
Slangroom @slangroom/db@${packageJson.version} Error: [DATABASE] Database error: TypeError: Cannot read properties of null (reading 'replace')
Heap:
{
"data": {
"myCache": "firstCache",
"myDb1": "sqlite://./test/db1.db",
"myDb2": "sqlite://./test/db2.db",
"myTable": "firstTable",
"myZenroomStringDictionary": {
"testkey": "test value"
},
"obj_1": "pippo",
"var_name": "obj_1"
},
"keys": {}
}
`);
});
26 changes: 26 additions & 0 deletions pkg/db/test/raw_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ Error colors:
- extra words
Slangroom @slangroom/db@${packageJson.version} Error: SQLITE_ERROR: no such table: member
Heap:
{
"data": {
"database": "sqlite://./test/fake_test.db",
"query_1": "INSERT INTO member (name) VALUES ('Alice')",
"query_5": "INSERT INTO member (name) VALUES (?)",
"query5_params": [
"Eve"
]
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -151,5 +164,18 @@ Error colors:
- extra words
Slangroom @slangroom/db@${packageJson.version} Error: SQLITE_ERROR: near "INSTERT": syntax error
Heap:
{
"data": {
"database": "sqlite://./test/test.db",
"query_1": "INSTERT INTO member (name) VALUES ('Alice')",
"query_5": "INSERT INTO member (name) VALUES (?)",
"query5_params": [
"Eve"
]
},
"keys": {}
}
`);
});
42 changes: 42 additions & 0 deletions pkg/fs/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Error colors:
- extra words
Slangroom @slangroom/fs@${packageJson.version} Error: $FILES_DIR must be provided
Heap:
{
"data": {
"filename": "test.txt"
},
"keys": {}
}
`);
});

Expand All @@ -65,6 +73,14 @@ Error colors:
- extra words
Slangroom @slangroom/fs@${packageJson.version} Error: ENOENT: no such file or directory, open 'test.txt'
Heap:
{
"data": {
"filename": "test.txt"
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -108,6 +124,16 @@ Error colors:
- extra words
Slangroom @slangroom/fs@${packageJson.version} Error: path must be string
Heap:
{
"data": {
"filename": {
"path": "test.txt"
}
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -150,6 +176,14 @@ Error colors:
- extra words
Slangroom @slangroom/fs@${packageJson.version} Error: no such file or directory: test/test_not_exist.txt
Heap:
{
"data": {
"filename": "test_not_exist.txt"
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -182,6 +216,14 @@ Error colors:
- extra words
Slangroom @slangroom/fs@${packageJson.version} Error: file or directory found under: test/test.txt
Heap:
{
"data": {
"filename": "test.txt"
},
"keys": {}
}
`);
const resultNotExists = slangroom.execute(verifyDoesNotExists, {
data: {
Expand Down
19 changes: 19 additions & 0 deletions pkg/git/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ Error colors:
- extra words
Slangroom @slangroom/git@${packageJson.version} Error: Could not find git root for ..
Heap:
{
"data": {
"path": "some/dumb/path",
"verified_git_repo": "true"
},
"keys": {}
}
`);
})

Expand Down Expand Up @@ -74,6 +83,16 @@ Error colors:
- extra words
Slangroom @slangroom/git@${packageJson.version} Error: HTTP Error: 401 Unauthorized
Heap:
{
"data": {
"url": "https://github.com/matteo-cristino/dumb",
"path": "another/dumb/path",
"cloned_repository": "true"
},
"keys": {}
}
`);
})

Expand Down
18 changes: 18 additions & 0 deletions pkg/helpers/test/pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ None of the properties
}
}
}
Heap:
{
"data": {
"props": "a",
"complex_object": {
"r": {
"a": "b",
"c": {
"d": {
"e": 42
}
}
}
}
},
"keys": {}
}
`);
});

8 changes: 8 additions & 0 deletions pkg/http/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,13 @@ Error colors:
- extra words
Slangroom @slangroom/http@${packageJson.version} Error: sequential requests are not implemented
Heap:
{
"data": {
"greeting_es": "http://localhost/greeting-es"
},
"keys": {}
}
`);
});
8 changes: 8 additions & 0 deletions pkg/pocketbase/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Error colors:
- extra words
Slangroom @slangroom/pocketbase@${packageJson.version} Error: Can not start capacitor client in node environment
Heap:
{
"data": {
"pb_address": "http://127.0.0.1:8090/"
},
"keys": {}
}
`);
});

Expand Down
16 changes: 16 additions & 0 deletions pkg/shell/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ Error colors:
Slangroom @slangroom/shell@${packageJson.version} Error: Command failed with ENOENT: notfound -v
spawn notfound ENOENT
Heap:
{
"data": {
"c": "notfound -v"
},
"keys": {}
}
`);
});

Expand Down Expand Up @@ -92,5 +100,13 @@ Error colors:
Slangroom @slangroom/shell@${packageJson.version} Error: Command failed with exit code 1: cat notfound.txt
cat: notfound.txt: No such file or directory
Heap:
{
"data": {
"c": "cat notfound.txt"
},
"keys": {}
}
`);
});

0 comments on commit a03e20e

Please sign in to comment.