Skip to content

Commit 847448c

Browse files
authored
Merge pull request #83 from Mogztter/asciidoctor-2-0-0-timings-api
Use the new Timings API to remove Opal usage
2 parents 0c3f254 + 67af289 commit 847448c

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/invoker.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global Opal */
21
const fs = require('fs')
32
const ospath = require('path')
43
const asciidoctor = require('@asciidoctor/core')()
@@ -61,10 +60,10 @@ CLI version ${pkg.version}`
6160
static convertFromStdin (options, args) {
6261
stdin.read((data) => {
6362
if (args['timings']) {
64-
const timings = asciidoctor.Timings.$new()
65-
const instanceOptions = Object.assign({}, options, { timings: timings })
63+
const timings = asciidoctor.Timings.create()
64+
const instanceOptions = Object.assign({}, options, { timings })
6665
Invoker.convert(asciidoctor.convert, data, instanceOptions)
67-
timings.$print_report(Opal.gvars.stderr, '-')
66+
timings.printReport(process.stderr, '-')
6867
} else {
6968
Invoker.convert(asciidoctor.convert, data, options)
7069
}
@@ -94,10 +93,10 @@ CLI version ${pkg.version}`
9493
console.log(`converting file ${file}`)
9594
}
9695
if (timings) {
97-
const timings = asciidoctor.Timings.$new()
98-
const instanceOptions = Object.assign({}, options, { timings: timings })
96+
const timings = asciidoctor.Timings.create()
97+
const instanceOptions = Object.assign({}, options, { timings })
9998
Invoker.convertFile(file, instanceOptions)
100-
timings.$print_report(Opal.gvars.stderr, file)
99+
timings.printReport(process.stderr, file)
101100
} else {
102101
Invoker.convertFile(file, options)
103102
}

test/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ describe('Help', () => {
151151
})
152152
})
153153

154+
describe('Print timings report', () => {
155+
it('should print timings report', () => {
156+
sinon.stub(process.stderr, 'write')
157+
sinon.stub(process, 'exit')
158+
try {
159+
new Invoker(new Options().parse(['node', 'asciidoctor', `${__dirname}/fixtures/sample.adoc`, '--timings', '-o', '-'])).invoke()
160+
expect(process.stderr.write.called).to.be.true()
161+
expect(process.stderr.write.getCall(0).args[0]).to.equal(`Input file: ${__dirname}/fixtures/sample.adoc`)
162+
expect(process.stderr.write.getCall(1).args[0]).to.include('Time to read and parse source:')
163+
expect(process.stderr.write.getCall(2).args[0]).to.include('Time to convert document:')
164+
expect(process.stderr.write.getCall(3).args[0]).to.include('Total time (read, parse and convert):')
165+
} finally {
166+
process.stderr.write.restore()
167+
process.exit.restore()
168+
}
169+
})
170+
})
171+
154172
describe('Version', () => {
155173
it('should print version if -v is specified as sole argument', () => {
156174
sinon.stub(console, 'log')

0 commit comments

Comments
 (0)