diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 789fe49..1957fad 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest - strategy: + strategy: # strategy 定义 job 的运行参数 matrix: node-version: [16.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ @@ -27,4 +27,4 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm i # Just run tests once - - run: npm test \ No newline at end of file + - run: npm test diff --git a/Readme.md b/Readme.md index 48612c6..5140de5 100644 --- a/Readme.md +++ b/Readme.md @@ -8,4 +8,13 @@ ### 注意 -大家可以选择 tapable@0.2,也可以选择 tapable@1.x,这个看大家个人喜好哈,虽然我用的是0.2 \ No newline at end of file +大家可以选择 tapable@0.2,也可以选择 tapable@1.x,这个看大家个人喜好哈,虽然我用的是0.2 + +### 项目克隆至本地之后, npm install 、 npm run test 之后报如下错误 +> Cannot start ChromeHeadless +> Can not find the binary C:\Users\唐明响\Desktop\前端进阶培训_极客时间\homework\homework2\node_modules\puppeteer\.local-chromium\win64-1022525\chrome-win\chrome.exe +> Please set env variable CHROME_BIN +> 此时只需要将 karma.conf.js 配置文件中的 +> process.env.CHROME_BIN = require('puppeteer').executablePath() 改为 +> process.env.CHROME_BIN = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' (即本地 Chrome 浏览器启动的路径即可) +> 参考 https://www.npmjs.com/package/karma-chrome-launcher diff --git a/karma.conf.js b/karma.conf.js index 9f54051..b28c843 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,8 @@ // Karma configuration // Generated on Fri Aug 11 2017 22:02:05 GMT+0800 (CST) -process.env.CHROME_BIN = require('puppeteer').executablePath() +// process.env.CHROME_BIN = require('puppeteer').executablePath() +process.env.CHROME_BIN = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' +console.log(process.env.CHROME_BIN); module.exports = function(config) { config.set({ diff --git a/lib/db.js b/lib/db.js index a1fe32c..404db26 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1,12 +1,48 @@ const Tapable = require('tapable') class DB extends Tapable { - constructor() { - // TODO + constructor(options) { + // TODO + super() + this.options = options } - request() { - // TODO + // request(options) { + // // TODO + // // return this.applyPluginsWaterfall('endpoint') // 1 + // // return this.applyPluginsWaterfall0('endpoint') // 1 + // // return this.applyPluginsBailResult('endpoint') // 1 + // // if (this.options) { + // // this.options = this.applyPluginsWaterfall0('options',this.options) // + // // } + // return this.applyPluginsBailResult('endpoint',options) // 1 2 + // } + + // request(options) { + // if (!this.options) { + // this.options = {} + // } + // Object.assign(this.options, options); + // this.options = this.applyPluginsWaterfall0('options',this.options) // + // return this.applyPluginsBailResult('endpoint', this.options) // 1 2 3 + // } + + request(params = {}) { + if (!this.options) { + this.options = {} + } + let newParams = Object.assign(params, this.options) + this.applyPluginsWaterfall0('options',newParams) + newParams = Object.assign(newParams, this.options) + return new Promise((resolve,reject) => { + this.applyPluginsBailResult('endpoint', newParams).then(res => { + // 超时 + // return this.applyPluginsWaterfall('judge',res) ? reject(res) : resolve(res) + return this.applyPluginsBailResult('judge',res) ? reject(res) : resolve(res) + }, res => { + return reject() + }) + }) } }