Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into text-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
micque01 committed Dec 12, 2023
2 parents 0d91070 + 3f4c781 commit b526b8d
Show file tree
Hide file tree
Showing 121 changed files with 9,805 additions and 14,708 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ module.exports = {
process: true,
},
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['node_modules', 'svelte.config.js', '.eslintrc.cjs'],
ignorePatterns: ['node_modules', 'svelte.config.js', '.eslintrc.cjs', "babel.config.cjs", "jest.config.js"],
};
5 changes: 5 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
],
};
19,531 changes: 6,025 additions & 13,506 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 25 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
"dev": "vite",
"start": "vite dist --host",
"check": "svelte-check --tsconfig ./tsconfig.json",
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"prettier": "prettier --write src/."
},
"jest": {
"globals": {
"ts-jest": {
"useESM": true
}
},
"verbose": true,
"testMatch": [
"<rootDir>/**/__tests__/*.test.ts"
],
Expand All @@ -35,60 +41,64 @@
"setupFilesAfterEnv": [
"<rootDir>/src/setup_tests.ts",
"jest-expect-message"
]
],
"transformIgnorePatterns": []
},
"devDependencies": {
"@babel/preset-env": "^7.21.4",
"@babel/preset-env": "^7.23.5",
"@bulatdashiev/svelte-slider": "^1.0.3",
"@smui/dialog": "^7.0.0-beta.3",
"@sveltejs/vite-plugin-svelte": "^2.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/svelte": "^3.2.2",
"@tsconfig/svelte": "^4.0.1",
"@types/browser-lang": "^0.1.1",
"@types/d3": "^7.4.1",
"@types/jest": "^29.5.1",
"@types/js-cookie": "^3.0.3",
"@types/node": "^18.16.0",
"@types/three": "^0.152.0",
"@types/web-bluetooth": "^0.0.17",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"babel-jest": "^29.5.0",
"babel-jest": "^29.7.0",
"eslint": "^8.43.0",
"eslint-plugin-svelte": "^2.32.1",
"eslint-plugin-svelte3": "^4.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-expect-message": "^1.1.3",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.0",
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^3.59.2",
"svelte-check": "^3.2.0",
"svelte-check": "^3.6.2",
"svelte-jester": "^2.3.2",
"svelte-preprocess": "^5.0.3",
"svelte-windicss-preprocess": "^4.2.2",
"ts-jest": "^29.1.0",
"@types/w3c-web-usb": "^1.0.6",
"ts-jest": "^29.1.1",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"vite": "^4.3.1",
"vite-plugin-environment": "^1.1.3",
"vite-plugin-windicss": "^1.8.10"
"vite-plugin-windicss": "^1.9.2"
},
"dependencies": {
"@microsoft/applicationinsights-web": "^3.0.0",
"@sgratzl/chartjs-chart-boxplot": "^4.2.4",
"@tensorflow/tfjs": "^4.4.0",
"@types/w3c-web-serial": "^1.0.6",
"@types/w3c-web-usb": "^1.0.6",
"bowser": "^2.11.0",
"browser-lang": "^0.2.1",
"chart.js": "^4.2.1",
"chartjs-chart-pcp": "^4.1.1",
"d3": "^7.8.5",
"dapjs": "^2.3.0",
"js-cookie": "^3.0.4",
"postcss": "^8.4.23",
"smoothie": "^1.36.1",
"svelte-i18n": "^4.0.0",
"svelte-skeleton": "^1.3.1",
"three": "^0.152.2",
"uuid4": "^2.0.3"
}
}
}
24 changes: 1 addition & 23 deletions src/StaticConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
* Static configuration values. These values are not expected to change, while the application is running.
*/
import { PinTurnOnState } from './components/output/PinSelectorUtil';
import { Axes, Filters, FilterType } from './script/datafunctions';
import MBSpecs from './script/microbit-interfacing/MBSpecs';
import { HexOrigin } from './script/microbit-interfacing/Microbits';

class StaticConfiguration {
// in milliseconds, how long should be wait for reconnect before determining something catestrophic happened during the process?
public static readonly reconnectTimeoutDuration: number = 7500;
public static readonly connectTimeoutDuration: number = 17000; // initial connection
public static readonly connectTimeoutDuration: number = 10000; // initial connection

// After how long should we consider the connection lost if ping was not able to conclude?
public static readonly connectionLostTimeoutDuration: number = 3000;
Expand Down Expand Up @@ -53,26 +52,5 @@ class StaticConfiguration {
versionNumbers.set(HexOrigin.PROPRIETARY, 1);
return versionNumbers.get(origin) !== version;
};

public static readonly initialMLSettings = {
duration: 1800,
numSamples: 80,
minSamples: 80,
automaticClassification: true,
updatesPrSecond: 4,
numEpochs: 80,
learningRate: 0.5,
includedAxes: [Axes.X, Axes.Y, Axes.Z],
includedFilters: new Set<FilterType>([
Filters.MAX,
Filters.MEAN,
Filters.MIN,
Filters.STD,
Filters.PEAKS,
Filters.ACC,
Filters.ZCR,
Filters.RMS,
]),
};
}
export default StaticConfiguration;
14 changes: 14 additions & 0 deletions src/__tests__/disabledtests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### Disabled tests

These are tests that have, for some reason been disabled.

### 4. dec 2023.

4 test suites have been disabled, because jest cannot parse top-level awaits.

- datafunctions
- i18n
- microbit-behaviours
- microbit-facade

Should be introduced if https://github.com/microbit-foundation/cctd-ml-machine/issues/407 is solved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* SPDX-License-Identifier: MIT
*/

import fs from 'fs';
import { determineFilter, Filters } from '../script/datafunctions';
import { doesNotThrow } from 'assert';
import { determineFilter, Filters } from '../../script/datafunctions';
function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] {
return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Initialization tests', () => {
languages: ['da', 'en'],
},
}));
const i18n = await import('../i18n');
const i18n = await import('../../i18n');
const getText = get(i18n.t);

const translatedText = getText('alert.isRecording');
Expand All @@ -41,7 +41,7 @@ describe('Initialization tests', () => {
languages: ['random-language'],
},
}));
const i18n = await import('../i18n');
const i18n = await import('../../i18n');
const getText = get(i18n.t);

const translatedText = getText('alert.isRecording');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* SPDX-License-Identifier: MIT
*/
import 'svelte-jester';
import Microbits from '../script/microbit-interfacing/Microbits';
import ConnectionBehaviours from '../script/connection-behaviours/ConnectionBehaviours';
import OutputBehaviour from '../script/connection-behaviours/OutputBehaviour';
import InputBehaviour from '../script/connection-behaviours/InputBehaviour';
import SpyConnectionBehaviour from './mocks/SpyConnectionBehaviour';
import MockBTDevice from './mocks/mock-microbit-bluetooth';
import Microbits from '../../script/microbit-interfacing/Microbits';
import ConnectionBehaviours from '../../script/connection-behaviours/ConnectionBehaviours';
import OutputBehaviour from '../../script/connection-behaviours/OutputBehaviour';
import InputBehaviour from '../../script/connection-behaviours/InputBehaviour';
import SpyConnectionBehaviour from '../mocks/SpyConnectionBehaviour';
import MockBTDevice from '../mocks/mock-microbit-bluetooth';

describe('Microbit behaviours tests', () => {
let spyInputBehaviour: SpyConnectionBehaviour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import 'svelte-jester';
import Microbits from '../script/microbit-interfacing/Microbits';
import ConnectionBehaviours from '../script/connection-behaviours/ConnectionBehaviours';
import OutputBehaviour from '../script/connection-behaviours/OutputBehaviour';
import InputBehaviour from '../script/connection-behaviours/InputBehaviour';
import SpyConnectionBehaviour from './mocks/SpyConnectionBehaviour';
import MockBTDevice from './mocks/mock-microbit-bluetooth';
import Microbits from '../../script/microbit-interfacing/Microbits';
import ConnectionBehaviours from '../../script/connection-behaviours/ConnectionBehaviours';
import OutputBehaviour from '../../script/connection-behaviours/OutputBehaviour';
import InputBehaviour from '../../script/connection-behaviours/InputBehaviour';
import SpyConnectionBehaviour from '../mocks/SpyConnectionBehaviour';
import MockBTDevice from '../mocks/mock-microbit-bluetooth';

describe('Microbit facade tests', () => {
let spyInputBehaviour: SpyConnectionBehaviour;
Expand All @@ -35,7 +35,7 @@ describe('Microbit facade tests', () => {
Object.assign(navigator, {
bluetooth: {
requestDevice(
options?: RequestDeviceOptions & { filters?: any | any[] },
options?: RequestDeviceOptions & { filters?: { namePrefix: string }[] },
): Promise<BluetoothDevice> {
const microBitName = 'vatav';
if (!options) {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('Microbit facade tests', () => {

test('Can connect the same microbit to output and input', async () => {
const wasConnected = await Microbits.assignInput('vatav');
await Microbits.useInputAsOutput();
Microbits.useInputAsOutput();
expect(wasConnected).toBeTruthy();
expect(Microbits.isOutputAssigned()).toBeTruthy();
expect(Microbits.isInputAssigned()).toBeTruthy();
Expand All @@ -106,7 +106,7 @@ describe('Microbit facade tests', () => {

test('When same, disconnecting input also disconnects output', async () => {
const wasConnected = await Microbits.assignInput('vatav');
await Microbits.useInputAsOutput();
Microbits.useInputAsOutput();
expect(wasConnected).toBeTruthy();
Microbits.expelInputAndOutput();
expect(Microbits.isOutputAssigned()).toBeFalsy();
Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/license-identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import 'jest-expect-message';
import * as path from 'path';

// Place files you wish to ignore by name in here
const ignoredFiles: RegExp[] = [/^\.DS_Store$/, /\.(gif|svg|png|jpg|jpeg)$/];
const ignoredFiles: RegExp[] = [
/^\.DS_Store$/,
/^ui.[a-z-]+.json$/,
/\.(gif|svg|png|jpg|jpeg)$/,
/^README.md$/,
];
const directoriesToScan = ['./src/', './microbit/v2/source/', './microbit/v1/source/'];

const licenseIdentifierStringSPDX = 'SPDX-License-Identifier:';
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/mocks/mock-bluetooth-info-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export class MockBluetoothModelNumberCharacteristic
readonly service: BluetoothRemoteGATTService;
readonly uuid: string = '';

constructor(public versionNumber: number, service: BluetoothRemoteGATTService) {
constructor(
public versionNumber: number,
service: BluetoothRemoteGATTService,
) {
this.service = service;
}

Expand Down
20 changes: 8 additions & 12 deletions src/__tests__/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@
*
* SPDX-License-Identifier: MIT
*/
import { translations } from '../translations';
import da from './../messages/ui.da.json';
import en from './../messages/ui.en.json';

describe('Translation tests', () => {
test('Should be same number of translations', () => {
const danishTranslationCount = Object.keys(translations.da).length;
const englishTranslationCount = Object.keys(translations.en).length;
const danishTranslationCount = Object.keys(da).length;
const englishTranslationCount = Object.keys(en).length;
expect(danishTranslationCount).toEqual(englishTranslationCount);
});

test('Translations are the same', () => {
const danishTranslationKeys = Object.getOwnPropertyNames(
translations.da,
) as (keyof typeof translations.da)[];
const danishTranslationKeys = Object.getOwnPropertyNames(da) as (keyof typeof da)[];
for (let i = 0; i < danishTranslationKeys.length; i++) {
const danishKey = danishTranslationKeys[i];
expect(
translations.en[danishKey],
`Something not the same -> ${danishKey}`,
).toBeDefined();
expect(en[danishKey], 'Something not the same -> ' + danishKey).toBeDefined();
}
});

// Mostly an architecture test
test('Translations should be in the same order', () => {
const danishTranslationKeys = Object.getOwnPropertyNames(translations.da);
const englishTranslationKeys = Object.getOwnPropertyNames(translations.en);
const danishTranslationKeys = Object.getOwnPropertyNames(da);
const englishTranslationKeys = Object.getOwnPropertyNames(en);
for (let i = 0; i < englishTranslationKeys.length; i++) {
const danishKey = danishTranslationKeys[i];
const englishKey = englishTranslationKeys[i];
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/unusedTranslations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SPDX-License-Identifier: MIT
*/

import { translations } from '../translations';
import en from './../messages/ui.en.json';
import * as fs from 'fs';
import * as path from 'path';

Expand Down Expand Up @@ -67,7 +67,7 @@ const filesIncludesExpression = (files: string[], expect: string): boolean => {
test(
'All translations should be used',
() => {
const translationKeys = Object.getOwnPropertyNames(translations.en);
const translationKeys = Object.getOwnPropertyNames(en);
const flatten = flattenDirectory('./src/');
for (let i = 0; i < translationKeys.length; i++) {
const translationKey = translationKeys[i];
Expand Down
Loading

0 comments on commit b526b8d

Please sign in to comment.