From 7edc30febe994d5106d04d6904bd1be7aaccb4e4 Mon Sep 17 00:00:00 2001 From: xiaoquan Date: Sun, 21 Aug 2022 17:55:42 +0800 Subject: [PATCH 1/2] complete homework2 --- lib/db.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/db.js b/lib/db.js index a1fe32c..e136e7c 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1,12 +1,31 @@ const Tapable = require('tapable') class DB extends Tapable { - constructor() { + constructor(options) { // TODO + super(); + // this.options = Object.assign(options) + this.options = options; } - request() { + request(params = {}) { // TODO + // 设置options插件 + let options = this.applyPluginsWaterfall('options', this.options) || {}; + + return new Promise((resolve, reject) => { + this.applyPluginsBailResult('endpoint', Object.assign(params, options)) + .then((res) => { + let judge = this.applyPluginsBailResult('judge', res); + if(!judge) { + resolve(res) + }else { + reject(res) + } + }, () => { + reject() + }) + }) } } From 0b0b1d6722bc7433449ebc55fbfcf245b654cd1e Mon Sep 17 00:00:00 2001 From: xiaoquan Date: Sun, 21 Aug 2022 22:40:09 +0800 Subject: [PATCH 2/2] replace karma with jest --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 94bd5ff..d678f94 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "test", "main": "index.js", "scripts": { - "test": "karma start" + "test": "jest" }, "repository": { "type": "git", @@ -26,5 +26,8 @@ "karma-webpack": "^2.0.4", "mocha": "^3.5.0", "webpack": "^3.5.3" + }, + "dependencies": { + "jest": "^28.1.3" } }