Skip to content

Commit

Permalink
Merge pull request #83 from Mogztter/asciidoctor-2-0-0-timings-api
Browse files Browse the repository at this point in the history
Use the new Timings API to remove Opal usage
  • Loading branch information
ggrossetie authored Jan 25, 2020
2 parents 0c3f254 + 67af289 commit 847448c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/invoker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global Opal */
const fs = require('fs')
const ospath = require('path')
const asciidoctor = require('@asciidoctor/core')()
Expand Down Expand Up @@ -61,10 +60,10 @@ CLI version ${pkg.version}`
static convertFromStdin (options, args) {
stdin.read((data) => {
if (args['timings']) {
const timings = asciidoctor.Timings.$new()
const instanceOptions = Object.assign({}, options, { timings: timings })
const timings = asciidoctor.Timings.create()
const instanceOptions = Object.assign({}, options, { timings })
Invoker.convert(asciidoctor.convert, data, instanceOptions)
timings.$print_report(Opal.gvars.stderr, '-')
timings.printReport(process.stderr, '-')
} else {
Invoker.convert(asciidoctor.convert, data, options)
}
Expand Down Expand Up @@ -94,10 +93,10 @@ CLI version ${pkg.version}`
console.log(`converting file ${file}`)
}
if (timings) {
const timings = asciidoctor.Timings.$new()
const instanceOptions = Object.assign({}, options, { timings: timings })
const timings = asciidoctor.Timings.create()
const instanceOptions = Object.assign({}, options, { timings })
Invoker.convertFile(file, instanceOptions)
timings.$print_report(Opal.gvars.stderr, file)
timings.printReport(process.stderr, file)
} else {
Invoker.convertFile(file, options)
}
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ describe('Help', () => {
})
})

describe('Print timings report', () => {
it('should print timings report', () => {
sinon.stub(process.stderr, 'write')
sinon.stub(process, 'exit')
try {
new Invoker(new Options().parse(['node', 'asciidoctor', `${__dirname}/fixtures/sample.adoc`, '--timings', '-o', '-'])).invoke()
expect(process.stderr.write.called).to.be.true()
expect(process.stderr.write.getCall(0).args[0]).to.equal(`Input file: ${__dirname}/fixtures/sample.adoc`)
expect(process.stderr.write.getCall(1).args[0]).to.include('Time to read and parse source:')
expect(process.stderr.write.getCall(2).args[0]).to.include('Time to convert document:')
expect(process.stderr.write.getCall(3).args[0]).to.include('Total time (read, parse and convert):')
} finally {
process.stderr.write.restore()
process.exit.restore()
}
})
})

describe('Version', () => {
it('should print version if -v is specified as sole argument', () => {
sinon.stub(console, 'log')
Expand Down

0 comments on commit 847448c

Please sign in to comment.