mirror of
https://github.com/TurboWarp/packager.git
synced 2024-11-25 16:35:59 +08:00
Start writing tests
This commit is contained in:
parent
a737a0c90b
commit
58fe62d911
2
.github/workflows/node.js.yml
vendored
2
.github/workflows/node.js.yml
vendored
@ -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
3
babel.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
|
||||
};
|
3837
package-lock.json
generated
3837
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
|
@ -75,7 +75,7 @@ class CloudManager {
|
||||
}
|
||||
}
|
||||
|
||||
class WebSocketProvider {
|
||||
class WebSocketProvider {
|
||||
constructor(cloudHost, projectId) {
|
||||
this.cloudHost = cloudHost;
|
||||
this.projectId = projectId;
|
||||
|
37
test/scaffolding/cloud.test.js
Normal file
37
test/scaffolding/cloud.test.js
Normal 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);
|
||||
});
|
Loading…
Reference in New Issue
Block a user