Skip to content

Commit d792871

Browse files
committed
fix: use strict test assertions
- 💄 updated README: dropped `2.x`, - set `engines.node`: `>=16.14.0`, and - simplified the description. Signed-off-by: dankeboy36 <[email protected]>
1 parent b42e8ca commit d792871

File tree

5 files changed

+68
-50
lines changed

5 files changed

+68
-50
lines changed

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# vscode-arduino-api
22

3-
Arduino API for [Arduino IDE 2.x](https://github.com/arduino/arduino-ide) external tools developers using VS Code extensions.
3+
[![Tests](https://github.com/dankeboy36/vscode-arduino-api/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/dankeboy36/vscode-arduino-api/actions/workflows/ci.yml)
44

5-
This VS Code extension does not provide any functionality but a bridge between the Arduino IDE 2.x and external tools implemented as a VS Code extension. Please reference [arduino/arduino-ide#58](https://github.com/arduino/arduino-ide/issues/58) to explain why this VSIX has been created. This extension has nothing to do with the [Visual Studio Code extension for Arduino](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino). This extension does not work in VS Code.
5+
[Arduino IDE](<(https://github.com/arduino/arduino-ide)>) API for VS Code extensions.
6+
7+
This VS Code extension does not provide any functionality but a bridge between the Arduino IDE and external tools implemented as a VS Code extension. Please reference [arduino/arduino-ide#58](https://github.com/arduino/arduino-ide/issues/58) to explain why this VSIX has been created.
8+
9+
> ⚠️ This extension has nothing to do with the [Visual Studio Code extension for Arduino](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino). This extension does not work in VS Code.
610
711
## API
812

@@ -67,12 +71,19 @@ If you want to use the Arduino APIs, you have to do the followings:
6771
}
6872
```
6973
74+
## Extension Settings
75+
76+
This extension contributes the following settings:
77+
78+
- `arduinoAPI.log`: set to `true` to enable logging of state updates. It's `false` by default.
79+
- `arduinoAPI.compareBeforeUpdate`: set to `true` to relax the state update. If `true`, a value will be updated when the new value and the current value are not [`deepStrictEqual`](https://nodejs.org/api/assert.html#comparison-details_1).
80+
7081
## FAQs
7182
7283
---
7384
7485
- Q: What does `@alpha` mean?
75-
- A: This API is in an alpha state and might change. The initial idea of this project was to establish a bare minimum layer and help Arduino IDE 2.x tool developers start with something. I make breaking changes only when necessary, keep it backward compatible, or provide a migration guide in the future. Please prepare for breaking changes.
86+
- A: This API is in an alpha state and might change. The initial idea of this project was to establish a bare minimum layer and help Arduino IDE tool developers start with something. I make breaking changes only when necessary, keep it backward compatible, or provide a migration guide in the future. Please prepare for breaking changes.
7687
7788
---
7889
@@ -86,5 +97,10 @@ If you want to use the Arduino APIs, you have to do the followings:
8697
8798
---
8899
100+
- Q: Are there any dependent examples?
101+
- A: Yes, for example, [dankeboy36/esp-exception-decoder](https://github.com/dankeboy36/esp-exception-decoder).
102+
103+
---
104+
89105
- Q: Are there plans to support it in VS Code?
90106
- A: Sure.

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "vscode-arduino-api",
3-
"displayName": "Arduino API for VS Code extensions",
4-
"description": "API for Arduino IDE 2.x external tools developers using VS Code extensions",
5-
"version": "0.1.1",
3+
"displayName": "Arduino IDE API for VS Code extensions",
4+
"description": "Lightweight API between the Arduino IDE and VS Code extensions",
5+
"version": "0.1.2",
66
"engines": {
7-
"vscode": "^1.78.0"
7+
"vscode": "^1.78.0",
8+
"node": ">=16.14.0"
89
},
910
"author": "dankeboy36",
1011
"publisher": "dankeboy36",
@@ -77,7 +78,7 @@
7778
"commands": [
7879
{
7980
"command": "arduinoAPI.updateState",
80-
"title": "Update the Arduino State"
81+
"title": "Update State"
8182
}
8283
],
8384
"menus": {

src/test/suite/arduinoContext.test.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import assert from 'assert';
1+
import assert from 'node:assert/strict';
22
import vscode from 'vscode';
33
import type {
44
ArduinoContext,
@@ -90,7 +90,7 @@ describe('arduinoContext', () => {
9090
this.slow(250);
9191
const property = <keyof ArduinoState>name;
9292
const value = arduinoContext[property];
93-
assert.deepEqual(value, undefined);
93+
assert.deepStrictEqual(value, undefined);
9494
const values: ArduinoState[keyof ArduinoState][] = [];
9595
toDispose.push(
9696
arduinoContext.onDidChange(property)((newValue) => {
@@ -99,9 +99,9 @@ describe('arduinoContext', () => {
9999
);
100100
await update(property, expectedValue);
101101
const newValue = arduinoContext[property];
102-
assert.deepEqual(newValue, expectedValue);
103-
assert.deepEqual(values.length, 1);
104-
assert.deepEqual(values[0], expectedValue);
102+
assert.deepStrictEqual(newValue, expectedValue);
103+
assert.deepStrictEqual(values.length, 1);
104+
assert.deepStrictEqual(values[0], expectedValue);
105105
})
106106
);
107107

@@ -149,11 +149,11 @@ describe('arduinoContext', () => {
149149
.getConfiguration('arduinoAPI')
150150
.inspect(configKey);
151151
assert.notEqual(actualInspect, undefined);
152-
assert.equal(actualInspect?.defaultValue, defaultValue);
152+
assert.strictEqual(actualInspect?.defaultValue, defaultValue);
153153
for (const testValue of testValues) {
154154
await updateWorkspaceConfig(configKey, testValue);
155155
const actualValue = getWorkspaceConfig(configKey);
156-
assert.equal(
156+
assert.strictEqual(
157157
actualValue,
158158
testValue,
159159
`failed to get expected config value for '${configKey}'`
@@ -181,12 +181,12 @@ describe('arduinoContext', () => {
181181
if (property === 'boardDetails') {
182182
// Fail when enhancement is implemented in the CLI.
183183
// https://github.com/arduino/arduino-cli/issues/2209
184-
assert.notDeepEqual(value, sameValue);
184+
assert.notDeepStrictEqual(value, sameValue);
185185
} else {
186-
assert.deepEqual(value, sameValue);
186+
assert.deepStrictEqual(value, sameValue);
187187
}
188188
await update(property, value);
189-
assert.deepEqual(arduinoContext[property], value);
189+
assert.deepStrictEqual(arduinoContext[property], value);
190190

191191
const updates: (typeof value | undefined)[] = [];
192192
toDispose.push(
@@ -197,39 +197,39 @@ describe('arduinoContext', () => {
197197

198198
await updateWorkspaceConfig('compareBeforeUpdate', true);
199199
await update(property, value);
200-
assert.equal(updates.length, 0);
200+
assert.strictEqual(updates.length, 0);
201201
await update(property, sameValue);
202202
if (property === 'boardDetails') {
203203
// See special handling of `boardDetails` above.
204-
assert.equal(updates.length, 1, JSON.stringify(updates));
204+
assert.strictEqual(updates.length, 1, JSON.stringify(updates));
205205
return this.skip();
206206
}
207-
assert.equal(updates.length, 0, JSON.stringify(updates[0]));
207+
assert.strictEqual(updates.length, 0, JSON.stringify(updates[0]));
208208

209209
await updateWorkspaceConfig('compareBeforeUpdate', false);
210210
await update(property, sameValue);
211-
assert.equal(updates.length, 1);
212-
assert.deepEqual(updates[0], sameValue);
213-
assert.deepEqual(updates[0], value);
211+
assert.strictEqual(updates.length, 1);
212+
assert.deepStrictEqual(updates[0], sameValue);
213+
assert.deepStrictEqual(updates[0], value);
214214

215215
await updateWorkspaceConfig('compareBeforeUpdate', true);
216216
await update(property, undefined);
217-
assert.equal(updates.length, 2);
218-
assert.deepEqual(updates[1], undefined);
217+
assert.strictEqual(updates.length, 2);
218+
assert.deepStrictEqual(updates[1], undefined);
219219
await update(property, sameValue);
220-
assert.equal(updates.length, 3);
221-
assert.deepEqual(updates[2], sameValue);
222-
assert.deepEqual(updates[2], value);
220+
assert.strictEqual(updates.length, 3);
221+
assert.deepStrictEqual(updates[2], sameValue);
222+
assert.deepStrictEqual(updates[2], value);
223223

224-
assert.deepEqual(arduinoContext[property], sameValue);
224+
assert.deepStrictEqual(arduinoContext[property], sameValue);
225225
})
226226
);
227227

228228
it('should error when disposed', async () => {
229-
assert.equal('dispose' in arduinoContext, true);
229+
assert.strictEqual('dispose' in arduinoContext, true);
230230
// eslint-disable-next-line @typescript-eslint/no-explicit-any
231231
const disposable = <{ dispose: unknown }>(arduinoContext as any);
232-
assert.equal(typeof disposable.dispose === 'function', true);
232+
assert.strictEqual(typeof disposable.dispose === 'function', true);
233233
(<{ dispose(): unknown }>disposable).dispose();
234234

235235
assert.throws(() => arduinoContext.fqbn, /Disposed/);

src/test/suite/inmemoryState.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import assert from 'assert';
1+
import assert from 'node:assert/strict';
22
import { InmemoryState } from '../../inmemoryState';
33

44
describe('inmemoryState', () => {
55
it('should get a value', async () => {
66
const state = new InmemoryState();
77
await state.update('alma', false);
8-
assert.equal(state.get('alma'), false);
8+
assert.strictEqual(state.get('alma'), false);
99
});
1010

1111
it('should get a value with a default', async () => {
1212
const state = new InmemoryState();
13-
assert.equal(state.get('alma'), undefined);
14-
assert.equal(state.get('alma', false), false);
13+
assert.strictEqual(state.get('alma'), undefined);
14+
assert.strictEqual(state.get('alma', false), false);
1515
});
1616

1717
it('should not modify the state when getting with default and the cache hits a miss', async () => {
1818
const state = new InmemoryState();
19-
assert.equal(state.get('alma', false), false);
19+
assert.strictEqual(state.get('alma', false), false);
2020
const actual = state.keys();
21-
assert.equal(actual.length, 0);
21+
assert.strictEqual(actual.length, 0);
2222
});
2323

2424
it('should retrieve the keys', async () => {
2525
const state = new InmemoryState();
2626
await state.update('alma', false);
2727
await state.update('korte', 36);
2828
const actual = state.keys();
29-
assert.equal(actual.length, 2);
30-
assert.equal(actual.includes('alma'), true);
31-
assert.equal(actual.includes('korte'), true);
29+
assert.strictEqual(actual.length, 2);
30+
assert.strictEqual(actual.includes('alma'), true);
31+
assert.strictEqual(actual.includes('korte'), true);
3232
});
3333

3434
it('should update with new value', async () => {
3535
const state = new InmemoryState();
3636
await state.update('alma', false);
37-
assert.equal(state.get('alma'), false);
37+
assert.strictEqual(state.get('alma'), false);
3838
await state.update('alma', 36);
39-
assert.equal(state.get('alma'), 36);
39+
assert.strictEqual(state.get('alma'), 36);
4040
const actual = state.keys();
41-
assert.equal(actual.length, 1);
42-
assert.equal(actual.includes('alma'), true);
41+
assert.strictEqual(actual.length, 1);
42+
assert.strictEqual(actual.includes('alma'), true);
4343
});
4444

4545
it('should remove when the update value is undefined', async () => {
4646
const state = new InmemoryState();
4747
await state.update('alma', false);
48-
assert.equal(state.get('alma'), false);
48+
assert.strictEqual(state.get('alma'), false);
4949
await state.update('alma', undefined);
50-
assert.equal(state.get('alma'), undefined);
50+
assert.strictEqual(state.get('alma'), undefined);
5151
const actual = state.keys();
52-
assert.equal(actual.length, 0);
52+
assert.strictEqual(actual.length, 0);
5353
});
5454
});

0 commit comments

Comments
 (0)