-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asciidoctor-Doctest Testing #116
Conversation
This is an incomplete pull on the old upstream doctest branch that I adapted based on asciidoctor-doctest's current README.
How did you generate files in |
Yes it is normal. The files in |
Ok so I need to generate one file per example in JavaScript to mimic what Asciidoctor Doctest is doing ? Currently Thanks |
The sooner we can get this merged, the better. Then we can all work on improving the examples. wdyt? |
I'm starting to upgrade Jade/Pug templates to use the new public API with Asciidoctor.js 1.5.6+. To make sure that I'm not breaking anything, I'm writing a test for each @obilodeau What's left to do ? |
I made a custom test working today. See The manual tests are not ported to the doctest setup and I'm still trying to workaround the fact that all my tests would need to be in a very large What would I need to do to test using the javascript toolchain? |
Turned out this was an assumption I made. I am converting the tests to doctest right now (adding metadata). Making some reorganization while I'm at it. But now I need to get some 🛌. So all Hopefully, that rendering will be stable enough between jade and slim so that we can use two different templating engine but only one HTML result set. We'll see soon enough. In the mean time, anything (instructions) that can help me run |
I think it won't be easy to cross compile The basic idea is to compare an input with an expected output: var asciidoctor = require('asciidoctor.js')();
require('asciidoctor-template.js');
require('../build/asciidoctor-revealjs.js');
var assert = require('assert');
var fs = require('fs');
describe('Rendering', function () {
var tests = [
{input: './test/block_admonition.adoc', expected: './test/block_admonition_output.html'},
{input: './test/block_audio.adoc', expected: './test/block_audio_output.html'},
{input: '...', expected: '...'}
];
tests.forEach(function (test) {
it('should produce a valid Reveal.js presentation for ' + test.input, function () {
var html = asciidoctor.convertFile(test.input, {safe: 'safe', backend: 'revealjs', to_file: false});
assert.equal(html, fs.readFileSync(test.expected, 'utf-8'));
});
});
}); |
The problem here is that we won't leverage doctest's power unless we reimplement it the same. Features like showing exactly where the problem is introduced with colorized diffs. Also, the output will probably be different since it will use another HTML beautifier and I'm afraid we won't be able to use the same test output for both slim and jade (ensuring compatibility between the two). That said, I think this is the only real option we've got for now unless asciidoctor-doctest's maintainer is interested in making it transcompilable. |
That's right, you will have the diff output of the chosen JavaScript framework. |
* test cases are now in examples/ which should make them easier to discover * rendered tests are in test/output/slim so we can have jade/ at some point * most test cases are not useful right now due to issue: asciidoctor/asciidoctor-doctest#12
That's done. I also moved the test cases to Because of asciidoctor/asciidoctor-doctest#12 most tests are useless now. Next up is travis-ci integration (running |
No, you don’t need. Doctest doesn’t need any deep integration with Asciidoctor, it can be modified to just call external program (asciidoctor.js) that accepts arguments and dumps output to stdout. @Mogztter #116 (comment):
No, one file may contain multiple examples, typically relevant to one particular AST node (e.g. @Mogztter #116 (comment):
You can, but really shouldn’t. It’d be just code duplication with all its drawbacks.
Why? This is not how it should be used.
Doctest “normalizes” HTML for comparison, so if both templates produce syntactically equal output (formatting, attributes order etc. is irrelevant), then they will be equal. Why do you need two sets of templates in two different templating engines? Asciidoctor.js is Asciidoctor transpiled to JS using Opal, right? Then why not to transpile even templates, specifically Ruby code generated by the template engine? You can use asciidoctor-templates-compiler to compile set of Slim templates into single Ruby file – Asciidoctor converter. When you avoid using Slim’s splat attributes (and maybe some other extra extensions), then the resulting code is standalone, i.e. doesn’t depend on Slim or Temple at all. I wrote it for asciidoctor-html5s. @Mogztter #116 (comment):
Why you would do that? That’s not needed at all.
I’m not gonna make doctest transcompilable, because it doesn’t make any sense for me. As I know, Asciidoctor.js runs on node.js, so it should be possible to call it externally as a command, pass it some arguments and gather HTML on stdout, shouldn’t be? That’s all what’s needed for integration with Doctest. It currently does not support this out-of-box, but I’d be happy to implement it. |
BTW, please use asciidoctor-doctest 2.0.0.beta.3 or dev branch, not the last stable or master branch. I’ve started almost complete rewrite/refactoring of doctest two years ago and came back to it few weeks ago. The new version is much easier to integrate into project and also more cleanly extensible. |
Thanks @jirutka for the detailed answers.
I think this right here is what we should evaluate first.
This would be an acceptable compromise if we can't get compiled templates to work. @mojavelinux, @Mogztter: thoughts?
Ok, I will update this PR so that we use 2.0.0.beta3. Edit: I updated task list at the top of the PR to reflect current status. |
asciidoctor-revealjs.gemspec
Outdated
@@ -29,4 +29,6 @@ Gem::Specification.new do |s| | |||
s.add_runtime_dependency 'thread_safe', '~> 0.3.5' | |||
|
|||
s.add_development_dependency 'rake', '~> 10.4.2' | |||
s.add_development_dependency 'asciidoctor-doctest', '~> 2.0.0.beta.4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d be better to fix this version (= 2.0.0.beta.4
), ’cause it’s a beta and there may come some incompatible changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a cybersecurity person and I think it's always better to enable upstream projects to patch their issues but I see your point. I'll pin to that version but I hope you'll keep us in the loop for improvements / security issues 😉
test/output/slim/block_audio.html
Outdated
<!-- .basic --> | ||
<div class="audioblock"> | ||
<div class="content"> | ||
<audio controls="" src="ocean_waves.mp3">Your browser does not support the audio tag.</audio> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be controls
, without =""
(and the same situation with loop
and some other attributes). This is problem with nokogiri, it doesn’t not support HTML5 well. :( However, you can manually fix it in generated examples, it can parse it well and assert passes. It’s not a big deal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File no longer exists after the refresh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah it's named audio.html
now. I fixed it. Commit coming soon.
</table> | ||
</div> | ||
|
||
<!-- .basic_multiline --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is outdated, I changed names format in beta.3 to use hyphen instead of underscore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the following to update them:
sed -Ei '/^<!-- \.(\w+) -->/ s/_/-/g' *.html
sed -Ei '/^<!-- \.(\w+)$/ s/_/-/g' *.html
However, there are more changes in admonition examples, so better to generate them from scratch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, and also I’ve dropped block_
prefix in beta.3, to be consistent with Asciidoctor (IIRC block_
prefix in node names is a legacy).
test/output/slim/document.html
Outdated
@@ -0,0 +1,2194 @@ | |||
<!-- .title --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document examples should be scoped (using :include:
option), look at https://github.com/jirutka/asciidoctor-html5s/blob/master/test/examples/html5/document.html for inspiration. (Just add :include:
options and run doctest:generate FORCE=y
to update them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now why the options were coming from the output document! Because I have no control on the input ones. Makes sense. Thanks for the pointer!
|
||
<!-- .link-with-target-blank --> | ||
|
||
<!-- .link-with-role --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These empty examples don’t look good… some error in reveal.js converter…?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it seems that you’ve somehow mixed examples generated using older DocTest version and the latest. It’d be better/easier to remove all output examples generated from reference examples and generate them from scratch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just done that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, the inline_anchor.html
template you mentioned just got re-generated the same way.
@jirutka: I addressed all your comments. |
Rakefile
Outdated
t.converter_opts = { template_dirs: 'templates/slim' } | ||
end | ||
|
||
# TODO add a rake task to render fully working examples to look at them in a browser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should maybe create an issue to not forget to do it 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you always grep for TODO|FIXME
before you do a release? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, do you ? I grep from time to time but it's not integrated in my development process.
That's why I like to create issues on GitHub so I can keep track of what needs to be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in e5fda00
I'm not an expert here but this looks fine to me. Good work 👍 |
There’s a lot of skipped examples (i.e. missing output examples), is it okay…? Run |
I think skipped examples are fine for now. We can open a compliance issue about them but I would put them out of scope for what we are trying to achieve here. |
Rakefile
Outdated
# :base_dir => 'examples' | ||
## :template_dir => 'templates/slim' | ||
system "bundle exec asciidoctor-revealjs data-background-oldstyle.adoc", :chdir => 'examples' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mogztter: I didn't manage to make convert_file
work. base_dir
was not honored. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that you may have to configure the safe
mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following seems to work:
Asciidoctor.convert_file 'data-background-newstyle.adoc',
:safe => 'safe',
:backend => 'revealjs',
:base_dir => 'examples'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not working for me:
$ bundle exec rake render
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - data-background-newstyle.adoc
/home/olivier/src/asciidoc/asciidoctor-reveal.js/.bundle/gems/ruby/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `initialize'
/home/olivier/src/asciidoc/asciidoctor-reveal.js/.bundle/gems/ruby/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `open'
/home/olivier/src/asciidoc/asciidoctor-reveal.js/.bundle/gems/ruby/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `convert_file'
/home/olivier/src/asciidoc/asciidoctor-reveal.js/Rakefile:19:in `block in <top (required)>'
/usr/bin/bundle:22:in `load'
/usr/bin/bundle:22:in `<main>'
Tasks: TOP => render
(See full trace by running task with --trace)
Should I change cwd
with Rake? Anyway, I want the output to be in examples/
and gitignore examples/reveal.js/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh I see... I didn't run the right Rake task 😳
convert_file
method does not use the base_dir
attribute so you'll have to use the full path (see asciidoctor.rb#convert_file)
What about:
Asciidoctor.convert_file 'examples/data-background-newstyle.adoc',
:safe => 'safe',
:backend => 'revealjs',
:base_dir => 'examples'
to_dir
should be relative to base_dir
so the document should be rendered in the examples/
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want the document to be rendered in examples/reveal.js/
, I think you need to define :to_dir => 'reveal.js'
.
(cherry picked from commit 1dfc983)
Please next time rebase PR before merging, i.e. remove fixup commits and other noise to get more clean repo history. |
The beginning of asciidoctor-doctest integration (#92).
At first, I thought this would help us test both slim and jade at the same time but I realize it would need a asciidoctor-doctest.js implementation. Maybe we could add a rake task to generate templates from the javascript/node toolchain and use doctest to do the diff. @Mogztter thoughts on this?
Test samples were generated from current back-end so I think some thought, reviews and more custom examples should be migrated before calling it a go.
Also Travis integration would be really nice.
Tasks
rake generate
(and rake test) asciidoctor-doctest#12Comments and further contributions welcome!