Skip to content
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

WIP: test: jasmine-ify original tests #1129

Closed
wants to merge 7 commits into from

Conversation

davisjam
Copy link
Contributor

@davisjam davisjam commented Mar 4, 2018

Jasmine-ifying original tests.

So far:

amsps_and_angles_encoding
auto_links
links_inline_style
inline_html_simple

  • Test(s) exist to ensure functionality and minimize regresstion (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

@davisjam davisjam requested a review from UziTech March 4, 2018 20:12
describe('integration suite', function () {
it('should put plaintext into a paragraph', function () {
expect(marked('Hello World!')).toBe('<p>Hello World!</p>\n');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to keep this test if we don't want to. I just added it as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually it'll go under a describe('plaintext') or something.

These are based on test/original/links_inline_style.md
@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

a693f23: implements suggestion from 1121. npm test will now run the old tests first.

@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

@UziTech

So these tests will be prettier if we can write code like this:

expect(marked(`[${desc.text}](${desc.link})`)).toBe(`<p><a href="${des

which is not "old node"-compliant (hence the travis failure).

Thoughts?

@UziTech
Copy link
Member

UziTech commented Mar 4, 2018

Ya we need to stick to es5 in the tests until we figure out a build step or drop node <6

@UziTech
Copy link
Member

UziTech commented Mar 4, 2018

I think the idea is v2.0 we will support only evergreen browsers and node >=6. At that time we will switch everything to ES6+

@joshbruce
Copy link
Member

@davisjam: Can't really read that. Newb-light is target.

@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

@joshbruce Acknowledged.

These are based on test/original/inline_html_simple.md
@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

@joshbruce Is the code in b681158 more readable?

@joshbruce
Copy link
Member

@davisjam: Try one test per example??

See also: #1124 (comment)

@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

@joshbruce Hesitant to do that since there would be a ton of boilerplate. Thoughts?

@joshbruce
Copy link
Member

@davisjam: I might need to slow down a bit in response time...really jazzed to see all the cooperation and collaboration...y'all are awesome!

...question:

Define "boilerplate" in this context?

Considerations (imho):

  1. Each test should be discreet (seem to remember there a mnemonic here STAR?? I think, COMET...I don't know): it('should pass CM 123' - this should help isolate which specific test scenario is failing without being the general heading "inline elements" and should be easier to migrate should the spec ever change...added new example -> add new test...changed specific example -> update.
  2. If we get an issue with a sample of MD and HTML - we can write it('should pass issue 1234 - to protect against regression and make triaging fixes easier.
  3. The size of the test bed shouldn't matter, if that's the concern related to boilerplate. It's mainly there to act as a technical specification for users to see how to use marked and get an idea of what to expect. If the test is in there, we say we can do it; if it's not...well. (Maybe we would do something like it('should fail CM 789' to let people know, "We don't support that example" (see the emphasis problem).

Having said that, I'm not a big fan of writing tests for their own sake...the fact we're doing this against a spec makes it a little more awkward than what I was doing there at the moment...partially, I think because our renderer is slightly complex compared to the type definition of an HTML element per #1102 (comment) - which is what I ended up with after starting with a PHP associative array (JSON). It makes the NPM package size bigger, but that's not what people are using operationally in their sites...if I have a question on why something is happening; instead of running to GitHub, I can run to the tests or spec (make sure I'm suing the right combination, make sure it's supported, then maybe post a PR to make the test pass).

Something like that...??

@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

Each test should be discreet

Yes. I'm writing tests at the level of "marked honors inline html" or "marked honors inline links". Spec-by-spec.

These are based on test/original/auto_links.md
@davisjam davisjam changed the title test: inline link tests WIP: test: jasmine-ify original tests Mar 4, 2018
@davisjam
Copy link
Contributor Author

davisjam commented Mar 4, 2018

Okie dokie, I'll leave this for now.

@joshbruce @UziTech Let me know how the current version looks.

These are based on test/original/amps_and_angles_encoding.md
@davisjam
Copy link
Contributor Author

davisjam commented Mar 5, 2018

Currently 'npm run lint' does not scan the new tests.

"lint": "eslint --fix lib/marked.js test/index.js",

Can we just replace "test/index.js" with "test/"? Seems to work.

@UziTech
Copy link
Member

UziTech commented Mar 5, 2018

@davisjam really we should add an .eslintignore file for marked.min.js (I'm pretty sure that is the only files we want to ignore) and use eslint --fix .

];

samples.forEach(function(sample) {
expect(marked(sample.md)).toBe(sample.html);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure out how to get a better error message other than expected 'some really long string' to equal 'some other really long string'.

We could try something like jasmine-diff-matchers

@@ -38,7 +38,7 @@
"uglify-js": "^3.3.10"
},
"scripts": {
"test": "jasmine --config=jasmine.json",
"test": "node test && jasmine --config=jasmine.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/specs/specs-spec.js already takes care of running the test/index.js tests in jasmine so there is no need to run node test.

@Feder1co5oave Feder1co5oave mentioned this pull request Mar 8, 2018
6 tasks
{'md': 'Inline [link](/script?foo=1&bar=2) with ampersands', 'html': '<p>Inline <a href="/script?foo=1&amp;bar=2">link</a> with ampersands</p>\n'},
{'md': '[link with ampersands](http://example.com/?foo=1&bar=)', 'html': '<p><a href="http://example.com/?foo=1&amp;bar=">link with ampersands</a></p>\n'},
{'md': '[link title with ampersands](http://att.com "AT&T")', 'html': '<p><a href="http://att.com" title="AT&amp;T">link title with ampersands</a></p>\n'},
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier to just pull these from their current files. I hate hard coding strings in javascript. Too much possibility for errors.

We could construct each test from the files and add the describe and it descriptions to the front-matter in the .md file

Copy link
Member

@UziTech UziTech Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe reorganize these tests and pull the describe description from the folder name and the it description from the file name

@joshbruce
Copy link
Member

See #1159

@UziTech
Copy link
Member

UziTech commented Apr 4, 2018

I think we should try to converge on a similar test pattern as #1160, adding a json file for the original test similar to commonmark.json

@joshbruce
Copy link
Member

joshbruce commented Apr 5, 2018

I think if we're going to Jasminify the legacy tests, we might be covered elsewhere. #1160, for example, should/would cover the CM tests; so, they can be removed. The GFM ones would be covered by the GFM tests that haven't been created yet. There may also be conflicts between the specs and what marked does (autolinks, for example, might include a mechanism not covered by CommonMark).

Point being I suppose that should we keep these around just because they've always been around? or, can we rationally deprecate (some, most, many of) them in favor of something more robust?

@UziTech
Copy link
Member

UziTech commented Apr 5, 2018

I like the idea of just having CommonMark and GFM tests and deprecating all other features in favor of making marked more extensible and less bloated.

We should probably keep the tests around until the options are removed (in 1.x or 2.x)

@UziTech
Copy link
Member

UziTech commented Mar 12, 2019

I'm closing this in favor of #1444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants