Skip to content

Commit c9343bb

Browse files
committed
tests (snapshot not yet reviewed)
Signed-off-by: Jens Reinecke <[email protected]>
1 parent 47a4d79 commit c9343bb

File tree

4 files changed

+161
-11
lines changed

4 files changed

+161
-11
lines changed

__mocks__/vscode.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
require('domain');
1818
const { URI } = require('vscode-uri');
19+
const path = require('path');
20+
const fs = require('fs');
1921

2022
module.exports = {
2123
EventEmitter: jest.fn(() => {
@@ -45,8 +47,18 @@ module.exports = {
4547
get: jest.fn(),
4648
})),
4749
fs: {
48-
readFile: jest.fn(),
49-
}
50+
readFile: jest.fn(uri => {
51+
const buffer = fs.readFileSync(uri.fsPath);
52+
return new Promise(resolve => resolve(new Uint8Array(buffer)));
53+
})
54+
},
55+
workspaceFolders: [
56+
{
57+
uri: URI.file(path.join(__dirname, '..')),
58+
name: 'folderName',
59+
index: 0
60+
}
61+
]
5062
},
5163
extensions: {
5264
getExtension: jest.fn(),
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CbuildRunReader parses 1`] = `
4+
{
5+
"compiler": "AC6",
6+
"debug-sequences": [
7+
{
8+
"blocks": [
9+
{
10+
"execute": "Write32(0x20000000, 0xA5A5A5A5);
11+
",
12+
},
13+
],
14+
"name": "MySequence",
15+
"pname": "Core0",
16+
},
17+
{
18+
"blocks": [
19+
{
20+
"execute": "DAP_Delay(500000); // Delay for 500ms
21+
",
22+
},
23+
],
24+
"name": "DebugDeviceUnlock",
25+
"pname": "Core0",
26+
},
27+
],
28+
"debug-topology": {
29+
"debugports": [
30+
{
31+
"accessports": [
32+
{
33+
"address": 0,
34+
"apid": 0,
35+
},
36+
{
37+
"address": 1048576,
38+
"apid": 1,
39+
},
40+
],
41+
"dpid": 0,
42+
},
43+
],
44+
"processors": [
45+
{
46+
"apid": 0,
47+
"pname": "Core0",
48+
},
49+
{
50+
"apid": 1,
51+
"pname": "Core1",
52+
},
53+
],
54+
},
55+
"debugger": [
56+
{
57+
"clock": 10000000,
58+
"name": "<default>",
59+
"port": "swd",
60+
},
61+
],
62+
"device": "MyVendor::MyDevice",
63+
"device-pack": "MyVendor::[email protected]",
64+
"generated-by": "csolution version 2.8.0",
65+
"output": [
66+
{
67+
"file": "out/MyApp.bin",
68+
"info": "generate by MyApp",
69+
"type": "bin",
70+
},
71+
{
72+
"file": "out/out/MyApp.axf",
73+
"info": "generate by MyApp",
74+
"type": "elf",
75+
},
76+
],
77+
"programming": [
78+
{
79+
"algorithm": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Flash/algorithms/MyAlgorithm_Core0.FLM",
80+
"default": true,
81+
"pname": "Core0",
82+
"ram-size": 131072,
83+
"ram-start": 536870912,
84+
"size": 524288,
85+
"start": 0,
86+
},
87+
{
88+
"algorithm": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Flash/algorithms/MyAlgorithm_Extern.FLM",
89+
"default": true,
90+
"pname": "Core0",
91+
"ram-size": 131072,
92+
"ram-start": 536870912,
93+
"size": 33554432,
94+
"start": 3221225472,
95+
},
96+
],
97+
"solution": "my-test.csolution.yml",
98+
"system-descriptions": [
99+
{
100+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd",
101+
"pname": "Core0",
102+
"type": "svd",
103+
},
104+
],
105+
"system-resources": {
106+
"memory": [
107+
{
108+
"access": "rx",
109+
"default": true,
110+
"from-pack": "MyVendor::[email protected]",
111+
"name": "Flash",
112+
"pname": "Core0",
113+
"size": 524288,
114+
"start": 0,
115+
},
116+
{
117+
"access": "rwx",
118+
"default": true,
119+
"from-pack": "MyVendor::[email protected]",
120+
"name": "SRAM0",
121+
"pname": "Core0",
122+
"size": 4194304,
123+
"start": 33554432,
124+
},
125+
{
126+
"access": "rwx",
127+
"default": true,
128+
"from-pack": "MyVendor::[email protected]",
129+
"name": "SRAM1",
130+
"pname": "Core0",
131+
"size": 2621440,
132+
"start": 134217728,
133+
},
134+
],
135+
},
136+
"target-type": "My-Test-Target-Type",
137+
}
138+
`;

src/cbuild-run/cbuild-run-reader.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616

1717
import { CbuildRunReader } from './cbuild-run-reader';
1818

19-
const TEST_CBUILD_RUN_FILE = '../test-data/multi-core.cbuild-run.yml';
19+
const TEST_CBUILD_RUN_FILE = 'test-data/multi-core.cbuild-run.yml'; // Relative to repo root
20+
const TEST_FILE_PATH = 'test-data/fileReaderTest.txt'; // Relative to repo root
2021

2122
describe('CbuildRunReader', () => {
2223

23-
it.skip('parses', async () => {
24+
it('successfully parses a *.cbuild-run.yml file', async () => {
2425
const reader = new CbuildRunReader();
2526
const contents = await reader.parse(TEST_CBUILD_RUN_FILE);
2627
expect(contents).toMatchSnapshot();
2728
});
2829

30+
it('throws if it parses something other than a *.cbuild-run.yml file', async () => {
31+
const expectedError = /Invalid '\*\.cbuild-run\.yml' file: .*test-data\/fileReaderTest\.txt/;
32+
const reader = new CbuildRunReader();
33+
await expect(reader.parse(TEST_FILE_PATH)).rejects.toThrow(expectedError);
34+
});
2935
});

src/desktop/file-reader.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as vscode from 'vscode';
18-
import * as fs from 'fs';
1917
import { VscodeFileReader } from './file-reader';
2018

21-
const TEST_FILE_PATH = './../../test-data/fileReaderTest.txt';
19+
const TEST_FILE_PATH = 'test-data/fileReaderTest.txt'; // Relative to repo root
2220
const TEST_FILE_CONTENTS = 'Simple file';
2321

2422
describe('FileReader', () => {
2523
it('parses a simple file', async () =>{
26-
(vscode.workspace.fs.readFile as jest.Func) = (uri: vscode.Uri): Thenable<Uint8Array> => {
27-
const buffer = fs.readFileSync(uri.fsPath);
28-
return new Promise(resolve => resolve(new Uint8Array(buffer)));
29-
};
3024
const fileReader = new VscodeFileReader();
3125
const fileContents = await fileReader.readFileToString(TEST_FILE_PATH);
3226
expect(fileContents).toEqual(TEST_FILE_CONTENTS);

0 commit comments

Comments
 (0)