[Pkg-javascript-commits] [node-tap] 11/186: all your Base are belong to class

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:38 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit 57ac9541171c177a332b86041d1a3161e9019871
Author: isaacs <i at izs.me>
Date:   Sat Jul 8 21:53:10 2017 -0700

    all your Base are belong to class
---
 lib/base.js  | 402 +++++++++++++++++++++++++++++------------------------------
 lib/stdin.js |   3 +-
 2 files changed, 202 insertions(+), 203 deletions(-)

diff --git a/lib/base.js b/lib/base.js
index 4d0d40e..3d8b228 100644
--- a/lib/base.js
+++ b/lib/base.js
@@ -12,239 +12,239 @@ const cleanYamlObject = require('./clean-yaml-object.js')
 
 const domain = require('domain')
 const util = require('util')
-util.inherits(Base, Readable)
 
 const Parser = require('tap-parser')
 
 const ownOr = require('own-or')
 const ownOrEnv = require('own-or-env')
 
-function Base (options) {
-  this.start = 0
-  this.hrtime = null
-  this.time = null
-  this.readyToProcess = false
-  this.options = options
-  this.grep = ownOr(options, 'grep', [])
-  this.grepInvert = ownOr(options, 'grepInvert', false)
-  this.parent = ownOr(options, 'parent', null)
-  this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true)
-  this.name = ownOr(options, 'name', '')
-  if (!this.name)
-    this.name = ''
-  else
-    this.name = this.name.replace(/[\n\r\s\t]/g, ' ')
-  this.indent = ownOr(options, 'indent', '')
-  this.silent = !!options.silent
-  this.buffered = !!options.buffered || !!options.silent
-  this.finished = false
-  this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true)
-  this.omitVersion = !!options.omitVersion
-  this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true)
-  this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0
-  this.skip = ownOr(options, 'skip', false)
-  this.todo = ownOr(options, 'todo', false)
-  this.runOnly = ownOr(options, 'runOnly', false)
-  this.setupParser(options)
-  this.finished = false
-  this.output = ''
-  this.results = null
-  this.bailedOut = false
-  if (this.skip || this.todo)
-    this.main = Base.prototype.main
-
-  Readable.apply(this, options)
-
-  domain.create().add(this)
-  this.domain.on('error', this.threw.bind(this))
-
-  if (typeof options.debug === 'boolean')
-    this.debug = options.debug ? debug : nodebug
-}
-
-Base.prototype.passing = function () {
-  return this.parser.ok
-}
+class Base extends Readable {
+  constructor (options) {
+    options = options || {}
+    super(options)
+    this.start = 0
+    this.hrtime = null
+    this.time = null
+    this.readyToProcess = false
+    this.options = options
+    this.grep = ownOr(options, 'grep', [])
+    this.grepInvert = ownOr(options, 'grepInvert', false)
+    this.parent = ownOr(options, 'parent', null)
+    this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true)
+    this.name = ownOr(options, 'name', '')
+    if (!this.name)
+      this.name = ''
+    else
+      this.name = this.name.replace(/[\n\r\s\t]/g, ' ')
+    this.indent = ownOr(options, 'indent', '')
+    this.silent = !!options.silent
+    this.buffered = !!options.buffered || !!options.silent
+    this.finished = false
+    this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true)
+    this.omitVersion = !!options.omitVersion
+    this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true)
+    this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0
+    this.skip = ownOr(options, 'skip', false)
+    this.todo = ownOr(options, 'todo', false)
+    this.runOnly = ownOr(options, 'runOnly', false)
+    this.setupParser(options)
+    this.finished = false
+    this.output = ''
+    this.results = null
+    this.bailedOut = false
+    if (this.skip || this.todo)
+      this.main = Base.prototype.main
+
+    domain.create().add(this)
+    this.domain.on('error', this.threw.bind(this))
+
+    const doDebug = typeof options.debug === 'boolean' ? options.debug
+      : /\btap\b/i.test(process.env.NODE_DEBUG || '')
+
+    if (doDebug)
+      this.debug = debug
+  }
 
-Base.prototype.setTimeout = function (n) {
-  if (!this.hrtime)
-    this.hrtime = process.hrtime()
-
-  if (!n) {
-    clearTimeout(this.timer)
-    this.timer = null
-  } else {
-    this.start = Date.now()
-    this.timer = setTimeout(this.timeout.bind(this), n)
-    if (this.timer.unref)
-      this.timer.unref()
+  passing () {
+    return this.parser.ok
   }
-}
 
-Base.prototype.threw = function (er, extra, proxy) {
-  if (this.name && !proxy)
-    er.test = this.name
-
-  const message = er.message
-
-  if (!extra)
-    extra = extraFromError(er, extra, this.options)
-
-  if (this.results || this.ended) {
-    this.results.ok = false
-    if (this.parent)
-      this.parent.threw(er, extra, true)
-    else if (!er.stack)
-      console.error(er)
-    else {
-      er.message = message
-      delete extra.stack
-      delete extra.at
-      console.error('%s: %s', er.name || 'Error', message)
-      console.error(er.stack.split(/\n/).slice(1).join('\n'))
-      console.error(extra)
+  setTimeout (n) {
+    if (!this.hrtime)
+      this.hrtime = process.hrtime()
+
+    if (!n) {
+      clearTimeout(this.timer)
+      this.timer = null
+    } else {
+      this.start = Date.now()
+      this.timer = setTimeout(this.timeout.bind(this), n)
+      if (this.timer.unref)
+        this.timer.unref()
     }
-  } else
-    this.parser.ok = false
+  }
 
-  return extra
-}
+  threw (er, extra, proxy) {
+    if (this.name && !proxy)
+      er.test = this.name
+
+    const message = er.message
+
+    if (!extra)
+      extra = extraFromError(er, extra, this.options)
+
+    if (this.results || this.ended) {
+      this.results.ok = false
+      if (this.parent)
+        this.parent.threw(er, extra, true)
+      else if (!er.stack)
+        console.error(er)
+      else {
+        er.message = message
+        delete extra.stack
+        delete extra.at
+        console.error('%s: %s', er.name || 'Error', message)
+        console.error(er.stack.split(/\n/).slice(1).join('\n'))
+        console.error(extra)
+      }
+    } else
+      this.parser.ok = false
+
+    return extra
+  }
 
-Base.prototype.timeout = function (options) {
-  this.setTimeout(false)
-  const er = new Error('timeout!')
-  options = options || {}
-  options.expired = options.expired || this.name
-  this.threw(new Error('timeout!'), options)
-}
+  timeout (options) {
+    this.setTimeout(false)
+    const er = new Error('timeout!')
+    options = options || {}
+    options.expired = options.expired || this.name
+    this.threw(new Error('timeout!'), options)
+  }
 
-Base.prototype.main = function (cb) {
-  cb()
-}
+  main (cb) {
+    cb()
+  }
 
-Base.prototype.online = function (line) {
-  this.debug('LINE %j', line)
-  return this.push(this.indent + line)
-}
+  online (line) {
+    this.debug('LINE %j', line)
+    return this.push(this.indent + line)
+  }
 
-Base.prototype.push = function (c, e) {
-  assert.equal(typeof c, 'string')
-  assert.equal(c.substr(-1), '\n')
+  push (c, e) {
+    assert.equal(typeof c, 'string')
+    assert.equal(c.substr(-1), '\n')
+
+    if (this.buffered) {
+      this.output += c
+      return true
+    }
 
-  if (this.buffered) {
-    this.output += c
-    return true
+    // We *always* want data coming out immediately.  Test runners have a
+    // very special relationship with zalgo. It's more important to ensure
+    // that any console.log() lines that appear in the midst of tests are
+    // not taken out of context
+    if (this._readableState) {
+      this._readableState.sync = false
+    }
+
+    // this.debug(this._readableState)
+    return super.push(c, e)
   }
 
-  // We *always* want data coming out immediately.  Test runners have a
-  // very special relationship with zalgo. It's more important to ensure
-  // that any console.log() lines that appear in the midst of tests are
-  // not taken out of context
-  if (this._readableState) {
-    this._readableState.sync = false
+  onbail (reason) {
+    this.bailedOut = reason || true
+    this.emit('bailout', reason)
   }
 
-  // this.debug(this._readableState)
-  return Readable.prototype.push.call(this, c, e)
-}
+  oncomplete (results) {
+    if (this.hrtime) {
+      this.hrtime = process.hrtime(this.hrtime)
+      this.time = Math.round(this.hrtime[0] * 1e6 + this.hrtime[1] / 1e3) / 1e3
+    }
 
-Base.prototype.onbail = function (reason) {
-  this.bailedOut = reason || true
-  this.emit('bailout', reason)
-}
+    this.debug('ONCOMPLETE %j %j', this.name, results)
 
-Base.prototype.oncomplete = function (results) {
-  if (this.hrtime) {
-    this.hrtime = process.hrtime(this.hrtime)
-    this.time = Math.round(this.hrtime[0] * 1e6 + this.hrtime[1] / 1e3) / 1e3
-  }
+    if (this.results)
+      Object.keys(this.results)
+        .forEach(k => results[k] = this.results[k])
 
-  this.debug('ONCOMPLETE %j %j', this.name, results)
+    this.results = results
+    this.emit('complete', results)
+    const failures = results.failures
+      .filter(f => f.tapError)
+      .map(f => {
+        delete f.diag
+        delete f.ok
+        return f
+      })
 
-  if (this.results)
-    Object.keys(this.results).forEach(function (k) {
-      results[k] = this.results[k]
-    }, this)
+    if (failures.length)
+      this.options.failures = failures
 
-  this.results = results
-  this.emit('complete', results)
-  const failures = results.failures.filter(function (f) {
-    delete f.diag
-    delete f.ok
-    return f.tapError
-  })
+    this.onbeforeend()
+    this.emit('end')
+    this.ondone()
+  }
 
-  if (failures.length)
-    this.options.failures = failures
+  onbeforeend () {}
+  ondone () {}
+
+  setupParser (options) {
+    this.parser = new Parser({
+      bail: this.bail,
+      strict: this.strict,
+      omitVersion: this.omitVersion,
+      preserveWhitespace: this.preserveWhitespace
+    })
+    assert(this.parser.preserveWhitespace)
+    this.parser.on('line', this.online.bind(this))
+    this.parser.once('bailout', this.onbail.bind(this))
+    this.parser.on('complete', this.oncomplete.bind(this))
+  }
 
-  this.onbeforeend()
-  this.emit('end')
-  this.ondone()
-}
+  _read (n) {
+    // this.emit('readable')
+    // this.debug('_read %j', this.name, arguments)
+  }
 
-Base.prototype.onbeforeend = function () {}
-Base.prototype.ondone = function () {}
-
-Base.prototype.setupParser = function (options) {
-  this.parser = new Parser({
-    bail: this.bail,
-    strict: this.strict,
-    omitVersion: this.omitVersion,
-    preserveWhitespace: this.preserveWhitespace
-  })
-  assert(this.parser.preserveWhitespace)
-  this.parser.on('line', this.online.bind(this))
-  this.parser.once('bailout', this.onbail.bind(this))
-  this.parser.on('complete', this.oncomplete.bind(this))
-}
+  inspect () {
+    return this.constructor.name + ' ' + util.inspect({
+      name: this.name,
+      jobs: this.jobs,
+      buffered: this.buffered,
+      occupied: this.occupied,
+      pool: this.pool,
+      queue: this.queue,
+      subtests: this.subtests,
+      output: this.output,
+      skip: this.skip,
+      todo: this.todo,
+      only: this.only,
+      results: this.results,
+      options: [
+        'autoend',
+        'command',
+        'args',
+        'stdio',
+        'env',
+        'cwd',
+        'exitCode',
+        'signal',
+        'expired',
+        'timeout',
+        'at',
+        'skip',
+        'todo',
+        'only'
+      ].filter(k => this.options[k] !== undefined)
+        .reduce((s, k) => (s[k] = this.options[k], s), {})
+    })
+  }
 
-Base.prototype._read = function (n) {
-  // this.emit('readable')
-  // this.debug('_read %j', this.name, arguments)
-}
+  debug () {}
 
-Base.prototype.inspect = function () {
-  return this.constructor.name + ' ' + util.inspect({
-    name: this.name,
-    jobs: this.jobs,
-    buffered: this.buffered,
-    occupied: this.occupied,
-    pool: this.pool,
-    queue: this.queue,
-    subtests: this.subtests,
-    output: this.output,
-    skip: this.skip,
-    todo: this.todo,
-    only: this.only,
-    results: this.results,
-    options: [
-      'autoend',
-      'command',
-      'args',
-      'stdio',
-      'env',
-      'cwd',
-      'exitCode',
-      'signal',
-      'expired',
-      'timeout',
-      'at',
-      'skip',
-      'todo',
-      'only'
-    ].reduce(function (set, k) {
-      if (this.options[k] !== undefined)
-        set[k] = this.options[k]
-      return set
-    }.bind(this), {})
-  })
 }
 
-Base.prototype.debug = (/\btap\b/i.test(process.env.NODE_DEBUG || ''))
-  ? debug : nodebug
-
-function nodebug () {}
-
 /* istanbul ignore next */
 function debug () {
   const prefix = 'TAP ' + process.pid + ' ' + this.name + ': '
diff --git a/lib/stdin.js b/lib/stdin.js
index 39e583d..79af532 100644
--- a/lib/stdin.js
+++ b/lib/stdin.js
@@ -8,7 +8,6 @@ class Stdin extends Base {
     options = options || {}
     super(options)
     options.name = ownOr(options, 'name', '/dev/stdin')
-    Base.call(this, options)
 
     // This has to be here for node 0.10's wonky streams
     this.stream = ownOr(options, 'tapStream', process.stdin)
@@ -24,7 +23,7 @@ class Stdin extends Base {
   }
 
   threw (er, extra, proxy) {
-    extra = Base.prototype.threw.call(this, er, extra, proxy)
+    extra = super.threw(er, extra, proxy)
     this.options = extra
     this.parser.abort(er.message, extra)
     this.parser.end()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list