Skip to content

Commit

Permalink
fix: use strict test assertions
Browse files Browse the repository at this point in the history
 - 💄 updated README: dropped `2.x`,
 - set `engines.node`: `>=16.14.0`, and
 - simplified the description.

Signed-off-by: dankeboy36 <[email protected]>
  • Loading branch information
dankeboy36 committed Jun 20, 2023
1 parent b42e8ca commit d792871
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 50 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# vscode-arduino-api

Arduino API for [Arduino IDE 2.x](https://github.com/arduino/arduino-ide) external tools developers using VS Code extensions.
[![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)

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.
[Arduino IDE](<(https://github.com/arduino/arduino-ide)>) API for VS Code extensions.

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.

> ⚠️ 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.
## API

Expand Down Expand Up @@ -67,12 +71,19 @@ If you want to use the Arduino APIs, you have to do the followings:
}
```
## Extension Settings
This extension contributes the following settings:
- `arduinoAPI.log`: set to `true` to enable logging of state updates. It's `false` by default.
- `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).
## FAQs
---
- Q: What does `@alpha` mean?
- 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.
- 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.
---
Expand All @@ -86,5 +97,10 @@ If you want to use the Arduino APIs, you have to do the followings:
---
- Q: Are there any dependent examples?
- A: Yes, for example, [dankeboy36/esp-exception-decoder](https://github.com/dankeboy36/esp-exception-decoder).
---
- Q: Are there plans to support it in VS Code?
- A: Sure.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "vscode-arduino-api",
"displayName": "Arduino API for VS Code extensions",
"description": "API for Arduino IDE 2.x external tools developers using VS Code extensions",
"version": "0.1.1",
"displayName": "Arduino IDE API for VS Code extensions",
"description": "Lightweight API between the Arduino IDE and VS Code extensions",
"version": "0.1.2",
"engines": {
"vscode": "^1.78.0"
"vscode": "^1.78.0",
"node": ">=16.14.0"
},
"author": "dankeboy36",
"publisher": "dankeboy36",
Expand Down Expand Up @@ -77,7 +78,7 @@
"commands": [
{
"command": "arduinoAPI.updateState",
"title": "Update the Arduino State"
"title": "Update State"
}
],
"menus": {
Expand Down
48 changes: 24 additions & 24 deletions src/test/suite/arduinoContext.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert';
import assert from 'node:assert/strict';
import vscode from 'vscode';
import type {
ArduinoContext,
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('arduinoContext', () => {
this.slow(250);
const property = <keyof ArduinoState>name;
const value = arduinoContext[property];
assert.deepEqual(value, undefined);
assert.deepStrictEqual(value, undefined);
const values: ArduinoState[keyof ArduinoState][] = [];
toDispose.push(
arduinoContext.onDidChange(property)((newValue) => {
Expand All @@ -99,9 +99,9 @@ describe('arduinoContext', () => {
);
await update(property, expectedValue);
const newValue = arduinoContext[property];
assert.deepEqual(newValue, expectedValue);
assert.deepEqual(values.length, 1);
assert.deepEqual(values[0], expectedValue);
assert.deepStrictEqual(newValue, expectedValue);
assert.deepStrictEqual(values.length, 1);
assert.deepStrictEqual(values[0], expectedValue);
})
);

Expand Down Expand Up @@ -149,11 +149,11 @@ describe('arduinoContext', () => {
.getConfiguration('arduinoAPI')
.inspect(configKey);
assert.notEqual(actualInspect, undefined);
assert.equal(actualInspect?.defaultValue, defaultValue);
assert.strictEqual(actualInspect?.defaultValue, defaultValue);
for (const testValue of testValues) {
await updateWorkspaceConfig(configKey, testValue);
const actualValue = getWorkspaceConfig(configKey);
assert.equal(
assert.strictEqual(
actualValue,
testValue,
`failed to get expected config value for '${configKey}'`
Expand Down Expand Up @@ -181,12 +181,12 @@ describe('arduinoContext', () => {
if (property === 'boardDetails') {
// Fail when enhancement is implemented in the CLI.
// https://github.com/arduino/arduino-cli/issues/2209
assert.notDeepEqual(value, sameValue);
assert.notDeepStrictEqual(value, sameValue);
} else {
assert.deepEqual(value, sameValue);
assert.deepStrictEqual(value, sameValue);
}
await update(property, value);
assert.deepEqual(arduinoContext[property], value);
assert.deepStrictEqual(arduinoContext[property], value);

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

await updateWorkspaceConfig('compareBeforeUpdate', true);
await update(property, value);
assert.equal(updates.length, 0);
assert.strictEqual(updates.length, 0);
await update(property, sameValue);
if (property === 'boardDetails') {
// See special handling of `boardDetails` above.
assert.equal(updates.length, 1, JSON.stringify(updates));
assert.strictEqual(updates.length, 1, JSON.stringify(updates));
return this.skip();
}
assert.equal(updates.length, 0, JSON.stringify(updates[0]));
assert.strictEqual(updates.length, 0, JSON.stringify(updates[0]));

await updateWorkspaceConfig('compareBeforeUpdate', false);
await update(property, sameValue);
assert.equal(updates.length, 1);
assert.deepEqual(updates[0], sameValue);
assert.deepEqual(updates[0], value);
assert.strictEqual(updates.length, 1);
assert.deepStrictEqual(updates[0], sameValue);
assert.deepStrictEqual(updates[0], value);

await updateWorkspaceConfig('compareBeforeUpdate', true);
await update(property, undefined);
assert.equal(updates.length, 2);
assert.deepEqual(updates[1], undefined);
assert.strictEqual(updates.length, 2);
assert.deepStrictEqual(updates[1], undefined);
await update(property, sameValue);
assert.equal(updates.length, 3);
assert.deepEqual(updates[2], sameValue);
assert.deepEqual(updates[2], value);
assert.strictEqual(updates.length, 3);
assert.deepStrictEqual(updates[2], sameValue);
assert.deepStrictEqual(updates[2], value);

assert.deepEqual(arduinoContext[property], sameValue);
assert.deepStrictEqual(arduinoContext[property], sameValue);
})
);

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

assert.throws(() => arduinoContext.fqbn, /Disposed/);
Expand Down
32 changes: 16 additions & 16 deletions src/test/suite/inmemoryState.test.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import assert from 'assert';
import assert from 'node:assert/strict';
import { InmemoryState } from '../../inmemoryState';

describe('inmemoryState', () => {
it('should get a value', async () => {
const state = new InmemoryState();
await state.update('alma', false);
assert.equal(state.get('alma'), false);
assert.strictEqual(state.get('alma'), false);
});

it('should get a value with a default', async () => {
const state = new InmemoryState();
assert.equal(state.get('alma'), undefined);
assert.equal(state.get('alma', false), false);
assert.strictEqual(state.get('alma'), undefined);
assert.strictEqual(state.get('alma', false), false);
});

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

it('should retrieve the keys', async () => {
const state = new InmemoryState();
await state.update('alma', false);
await state.update('korte', 36);
const actual = state.keys();
assert.equal(actual.length, 2);
assert.equal(actual.includes('alma'), true);
assert.equal(actual.includes('korte'), true);
assert.strictEqual(actual.length, 2);
assert.strictEqual(actual.includes('alma'), true);
assert.strictEqual(actual.includes('korte'), true);
});

it('should update with new value', async () => {
const state = new InmemoryState();
await state.update('alma', false);
assert.equal(state.get('alma'), false);
assert.strictEqual(state.get('alma'), false);
await state.update('alma', 36);
assert.equal(state.get('alma'), 36);
assert.strictEqual(state.get('alma'), 36);
const actual = state.keys();
assert.equal(actual.length, 1);
assert.equal(actual.includes('alma'), true);
assert.strictEqual(actual.length, 1);
assert.strictEqual(actual.includes('alma'), true);
});

it('should remove when the update value is undefined', async () => {
const state = new InmemoryState();
await state.update('alma', false);
assert.equal(state.get('alma'), false);
assert.strictEqual(state.get('alma'), false);
await state.update('alma', undefined);
assert.equal(state.get('alma'), undefined);
assert.strictEqual(state.get('alma'), undefined);
const actual = state.keys();
assert.equal(actual.length, 0);
assert.strictEqual(actual.length, 0);
});
});

0 comments on commit d792871

Please sign in to comment.