Start writing tests

This commit is contained in:
Thomas Weber 2021-06-16 22:19:39 -05:00
parent a737a0c90b
commit 58fe62d911
No known key found for this signature in database
GPG Key ID: 1A1FB2587304135F
6 changed files with 3885 additions and 3 deletions

View File

@ -16,5 +16,5 @@ jobs:
with:
node-version: 10.x
- run: npm ci
- run: npm run build --if-present
- run: npm run build
- run: npm test

3
babel.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};

3837
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"scripts": {
"start": "webpack serve",
"build": "webpack",
"watch": "webpack --watch"
"watch": "webpack --watch",
"test": "jest"
},
"author": "",
"license": "GPL-3.0",
@ -21,8 +22,12 @@
"svelte": "^3.38.2"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.5",
"babel-jest": "^27.0.2",
"css-loader": "^5.2.6",
"html-webpack-plugin": "^4.5.2",
"jest": "^27.0.4",
"style-loader": "^2.0.0",
"svelte-loader": "^3.1.2",
"url-loader": "^4.1.1",

View File

@ -75,7 +75,7 @@ class CloudManager {
}
}
class WebSocketProvider {
class WebSocketProvider {
constructor(cloudHost, projectId) {
this.cloudHost = cloudHost;
this.projectId = projectId;

View File

@ -0,0 +1,37 @@
import Cloud from '../../src/scaffolding/cloud';
const cloudManager = () => new Cloud.CloudManager({
vm: {
runtime: {
hasCloudData: () => true
}
}
});
const mockProvider = () => ({
enable: () => {},
handleUpdateVariable: jest.fn()
});
test('CloudManager providers and overrides', () => {
const manager = cloudManager();
const provider1 = mockProvider();
const provider2 = mockProvider();
expect(() => manager.addProviderOverride('test', provider1)).toThrow('Manager is not aware of this provider');
manager.addProvider(provider1);
manager.addProvider(provider2);
manager.updateVariable('test', '123');
expect(provider1.handleUpdateVariable).toHaveBeenCalledTimes(1);
expect(provider2.handleUpdateVariable).toHaveBeenCalledTimes(1);
manager.addProviderOverride('test', provider1);
manager.updateVariable('test', '456');
expect(provider1.handleUpdateVariable).toHaveBeenCalledTimes(2);
expect(provider2.handleUpdateVariable).toHaveBeenCalledTimes(1);
manager.addProviderOverride('test2', null);
manager.updateVariable('test2', '789');
expect(provider1.handleUpdateVariable).toHaveBeenCalledTimes(2);
expect(provider2.handleUpdateVariable).toHaveBeenCalledTimes(1);
});