test(stack/storage): updates dependencies and add missing tests

This commit is contained in:
Pascal Precht 2020-03-02 11:14:23 +01:00 committed by Pascal Precht
parent 471a33a331
commit c9a35faa1e
4 changed files with 186 additions and 7 deletions

View File

@ -37,13 +37,18 @@
"_typecheck": "npm run solo -- typecheck",
"ci": "npm run qa",
"clean": "npm run reset",
"lint": "eslint src/",
"lint": "eslint src/ test/",
"qa": "npm-run-all lint _typecheck _build",
"reset": "npx rimraf dist embark-*.tgz package",
"solo": "embark-solo"
"solo": "embark-solo",
"test": "jest"
},
"eslintConfig": {
"extends": "../../../.eslintrc.json"
"extends": [
"../../../.eslintrc.json",
"plugin:jest/recommended",
"plugin:jest/style"
]
},
"dependencies": {
"@babel/runtime-corejs3": "7.8.4",
@ -55,14 +60,34 @@
"shelljs": "0.8.3"
},
"devDependencies": {
"@babel/core": "7.8.3",
"babel-jest": "25.1.0",
"embark-solo": "^5.2.3",
"embark-testing": "5.3.0-nightly.6",
"eslint": "6.8.0",
"eslint-plugin-jest": "22.5.1",
"npm-run-all": "4.1.5",
"rimraf": "3.0.0"
"rimraf": "3.0.0",
"sinon": "7.4.2"
},
"engines": {
"node": ">=10.17.0",
"npm": ">=6.11.3",
"yarn": ">=1.19.1"
},
"jest": {
"collectCoverage": true,
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.js"
],
"transform": {
"\\.(js|ts)$": [
"babel-jest",
{
"rootMode": "upward"
}
]
}
}
}

View File

@ -0,0 +1,125 @@
import sinon from 'sinon';
import assert from 'assert';
import { fakeEmbark } from 'embark-testing';
import Storage from '../src';
describe('stack/storage', () => {
let storage, embark;
beforeEach(() => {
const testBed = fakeEmbark({
storageConfig: {
dappConnection: {
foo: 'bar'
}
},
embarkConfig: {
generationDir: 'foo'
}
});
embark = testBed.embark;
storage = new Storage(embark, { plugins: testBed.plugins });
});
afterEach(() => {
embark.teardown();
sinon.restore();
});
describe('instantiation', () => {
it('should register storage:node:register command handler', () => {
storage.events.assert.commandHandlerRegistered('storage:node:register');
});
it('should register storage:node:start command handler', () => {
storage.events.assert.commandHandlerRegistered('storage:node:start');
});
it('should register storage:upload:register command handler', () => {
storage.events.assert.commandHandlerRegistered('storage:upload:register');
});
it('should register storage:upload command handler', () => {
storage.events.assert.commandHandlerRegistered('storage:upload');
});
});
it('should register a node', () => {
const startFunction = sinon.fake();
embark.events.request('storage:node:register', 'testNode', startFunction);
assert(storage.storageNodes['testNode']);
assert.equal(storage.storageNodes['testNode'], startFunction);
});
it('should start registered node', done => {
const startFunction = sinon.spy(cb => cb());
const storageConfig = {
enabled: true,
upload: {
provider: 'testProvider'
}
};
embark.events.request('storage:node:register', 'testProvider', startFunction);
embark.events.request('storage:node:start', storageConfig, () => {
assert(startFunction.calledOnce);
done();
});
});
it('should not start node if storage is disabled', done => {
const startFunction = sinon.spy(cb => cb());
const storageConfig = {
enabled: false,
upload: {
provider: 'testProvider'
}
};
embark.events.request('storage:node:register', 'testProvider', startFunction);
embark.events.request('storage:node:start', storageConfig, () => {
assert(!startFunction.calledOnce);
done();
});
});
it('should register an upload node', () => {
const uploadFn = sinon.fake();
embark.events.request('storage:upload:register', 'testNode', uploadFn);
assert(storage.uploadNodes['testNode']);
assert.equal(storage.uploadNodes['testNode'], uploadFn);
});
it('should upload data using registerd upload function', done => {
const uploadFn = sinon.spy(cb => cb());
embark.events.request('storage:upload:register', 'testNode', uploadFn);
embark.events.request('storage:upload', 'testNode', () => {
assert(uploadFn.calledOnce);
done();
});
});
it('should register action for pipeline:generateAll:before', done => {
const pipelineRegisterHandler = sinon.spy((params, cb) => cb());
embark.events.setCommandHandler('pipeline:register', pipelineRegisterHandler);
embark.plugins.runActionsForEvent('pipeline:generateAll:before', () => {
assert(pipelineRegisterHandler.calledOnce);
done();
});
});
});

View File

@ -18,6 +18,9 @@
},
{
"path": "../../core/utils"
},
{
"path": "../../utils/testing"
}
]
}

View File

@ -41,6 +41,27 @@
invariant "^2.2.4"
semver "^5.5.0"
"@babel/core@7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.8.3.tgz#30b0ebb4dd1585de6923a0b4d179e0b9f5d82941"
integrity sha512-4XFkf8AwyrEG7Ziu3L2L0Cv+WyY47Tcsp70JFmpftbAA1K7YL/sgE9jh9HyNj08Y/U50ItUchpN0w6HxAoX1rA==
dependencies:
"@babel/code-frame" "^7.8.3"
"@babel/generator" "^7.8.3"
"@babel/helpers" "^7.8.3"
"@babel/parser" "^7.8.3"
"@babel/template" "^7.8.3"
"@babel/traverse" "^7.8.3"
"@babel/types" "^7.8.3"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.1"
json5 "^2.1.0"
lodash "^4.17.13"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"
"@babel/core@7.8.4":
version "7.8.4"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.8.4.tgz#d496799e5c12195b3602d0fddd77294e3e38e80e"
@ -93,7 +114,7 @@
lodash "^4.17.13"
source-map "^0.5.0"
"@babel/generator@^7.8.4":
"@babel/generator@^7.8.3", "@babel/generator@^7.8.4":
version "7.8.7"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.8.7.tgz#870b3cf7984f5297998152af625c4f3e341400f7"
integrity sha512-DQwjiKJqH4C3qGiyQCAExJHoZssn49JTMJgZ8SANGgVFdkupcUhLOdkAeoC6kmHZCPfoDG5M0b6cFlSN5wW7Ew==
@ -339,7 +360,7 @@
"@babel/traverse" "^7.8.3"
"@babel/types" "^7.8.3"
"@babel/helpers@^7.8.4":
"@babel/helpers@^7.8.3", "@babel/helpers@^7.8.4":
version "7.8.4"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.8.4.tgz#754eb3ee727c165e0a240d6c207de7c455f36f73"
integrity sha512-VPbe7wcQ4chu4TDQjimHv/5tj73qz88o12EPkO2ValS2QiQS/1F2SsjyIGNnAD0vF/nZS6Cf9i+vW6HIlnaR8w==
@ -371,7 +392,7 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.6.tgz#ba5c9910cddb77685a008e3c587af8d27b67962c"
integrity sha512-trGNYSfwq5s0SgM1BMEB8hX3NDmO7EP2wsDGDexiaKMB92BaRpS+qZfpkMqUBhcsOTBwNy9B/jieo4ad/t/z2g==
"@babel/parser@^7.8.4":
"@babel/parser@^7.8.3", "@babel/parser@^7.8.4":
version "7.8.7"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.7.tgz#7b8facf95d25fef9534aad51c4ffecde1a61e26a"
integrity sha512-9JWls8WilDXFGxs0phaXAZgpxTZhSk/yOYH2hTHC0X1yC7Z78IJfvR1vJ+rmJKq3I35td2XzXzN6ZLYlna+r/A==
@ -8948,6 +8969,11 @@ eslint-plugin-import@~2.2.0:
minimatch "^3.0.3"
pkg-up "^1.0.0"
eslint-plugin-jest@22.5.1:
version "22.5.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.5.1.tgz#a31dfe9f9513c6af7c17ece4c65535a1370f060b"
integrity sha512-c3WjZR/HBoi4GedJRwo2OGHa8Pzo1EbSVwQ2HFzJ+4t2OoYM7Alx646EH/aaxZ+9eGcPiq0FT0UGkRuFFx2FHg==
eslint-plugin-jest@23.8.1:
version "23.8.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.8.1.tgz#247025e8a51b3a25a4cc41166369b0bfb4db83b7"