Browse Source

Rewrite tests to es6 modules

pull/979/head
Vitaly Puzrin 1 year ago
parent
commit
8980511a7a
  1. 8
      .eslintrc.yml
  2. 4
      package.json
  3. 3
      test/.eslintrc.yml
  4. 14
      test/babelmark-responder.mjs
  5. 17
      test/commonmark.mjs
  6. 19
      test/markdown-it.js
  7. 15
      test/markdown-it.mjs
  8. 10
      test/misc.mjs
  9. 26
      test/pathological.mjs
  10. 7
      test/ruler.mjs
  11. 6
      test/token.mjs
  12. 22
      test/utils.mjs

8
.eslintrc.yml

@ -1,7 +1,11 @@
env: env:
node: true node: true
browser: false
es6: false overrides:
-
files: [ '*.mjs' ]
parserOptions:
sourceType: module
ignorePatterns: ignorePatterns:
- coverage/ - coverage/

4
package.json

@ -16,7 +16,7 @@
"markdown-it": "bin/markdown-it.js" "markdown-it": "bin/markdown-it.js"
}, },
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint --ext js --ext mjs .",
"test": "npm run lint && nyc mocha && node support/specsplit.js", "test": "npm run lint && nyc mocha && node support/specsplit.js",
"coverage": "npm run test && nyc report --reporter html", "coverage": "npm run test && nyc report --reporter html",
"report-coveralls": "nyc --reporter=lcov mocha", "report-coveralls": "nyc --reporter=lcov mocha",
@ -56,7 +56,7 @@
"express": "^4.14.0", "express": "^4.14.0",
"gh-pages": "^3.1.0", "gh-pages": "^3.1.0",
"highlight.js": "^10.7.2", "highlight.js": "^10.7.2",
"jest-worker": "^26.6.2", "jest-worker": "^29.7.0",
"markdown-it-abbr": "^1.0.4", "markdown-it-abbr": "^1.0.4",
"markdown-it-container": "^3.0.0", "markdown-it-container": "^3.0.0",
"markdown-it-deflist": "^2.0.0", "markdown-it-deflist": "^2.0.0",

3
test/.eslintrc.yml

@ -1,7 +1,6 @@
env: env:
node: true
mocha: true mocha: true
es6: true es6: true
parserOptions: parserOptions:
ecmaVersion: 2017 ecmaVersion: 2020

14
test/babelmark-responder.js → test/babelmark-responder.mjs

@ -1,22 +1,24 @@
'use strict'; import supertest from 'supertest';
import { execFile } from 'child_process';
import { readFileSync } from 'fs';
describe('babelmark responder app', function () { describe('babelmark responder app', function () {
var app; var app;
var PORT = 5005; var PORT = 5005;
var request = require('supertest')('http://127.0.0.1:' + PORT); var request = supertest('http://127.0.0.1:' + PORT);
function timeout(ms) { function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
before(async () => { before(async () => {
app = require('child_process').execFile( app = execFile(
'node', 'node',
[ '../support/babelmark-responder.js' ], [ '../support/babelmark-responder.js' ],
{ {
cwd: __dirname, cwd: new URL('.', import.meta.url),
env: Object.assign({}, process.env, { PORT: PORT }) env: Object.assign({}, process.env, { PORT: PORT })
} }
); );
@ -41,13 +43,15 @@ describe('babelmark responder app', function () {
it('do request', () => { it('do request', () => {
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version;
return request return request
.get('/?text=foo') .get('/?text=foo')
.expect(200) .expect(200)
.expect({ .expect({
html: '<p>foo</p>\n', html: '<p>foo</p>\n',
name: 'markdown-it', name: 'markdown-it',
version: require('../package.json').version version
}); });
}); });

17
test/commonmark.js → test/commonmark.mjs

@ -1,9 +1,8 @@
'use strict'; import { fileURLToPath } from 'node:url';
import { relative } from 'node:path';
import { load } from 'markdown-it-testgen';
var p = require('path'); import markdownit from '../index.js';
var load = require('markdown-it-testgen').load; import { assert } from 'chai';
var assert = require('chai').assert;
function normalize(text) { function normalize(text) {
@ -15,7 +14,7 @@ function generate(path, md) {
load(path, function (data) { load(path, function (data) {
data.meta = data.meta || {}; data.meta = data.meta || {};
var desc = data.meta.desc || p.relative(path, data.file); var desc = data.meta.desc || relative(path, data.file);
(data.meta.skip ? describe.skip : describe)(desc, function () { (data.meta.skip ? describe.skip : describe)(desc, function () {
data.fixtures.forEach(function (fixture) { data.fixtures.forEach(function (fixture) {
@ -29,7 +28,7 @@ function generate(path, md) {
describe('CommonMark', function () { describe('CommonMark', function () {
var md = require('../')('commonmark'); var md = markdownit('commonmark');
generate(p.join(__dirname, 'fixtures/commonmark/good.txt'), md); generate(fileURLToPath(new URL('fixtures/commonmark/good.txt', import.meta.url)), md);
}); });

19
test/markdown-it.js

@ -1,19 +0,0 @@
'use strict';
var path = require('path');
var generate = require('markdown-it-testgen');
describe('markdown-it', function () {
var md = require('../')({
html: true,
langPrefix: '',
typographer: true,
linkify: true
});
generate(path.join(__dirname, 'fixtures/markdown-it'), md);
});

15
test/markdown-it.mjs

@ -0,0 +1,15 @@
import { fileURLToPath } from 'node:url';
import generate from 'markdown-it-testgen';
import markdownit from '../index.js';
describe('markdown-it', function () {
var md = markdownit({
html: true,
langPrefix: '',
typographer: true,
linkify: true
});
generate(fileURLToPath(new URL('fixtures/markdown-it', import.meta.url)), md);
});

10
test/misc.js → test/misc.mjs

@ -1,8 +1,6 @@
'use strict'; import { assert } from 'chai';
import markdownit from '../index.js';
import forInline from 'markdown-it-for-inline';
var assert = require('chai').assert;
var markdownit = require('../');
describe('API', function () { describe('API', function () {
@ -269,7 +267,7 @@ describe('Misc', function () {
it('Should render link target attr', function () { it('Should render link target attr', function () {
var md = markdownit() var md = markdownit()
.use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) { .use(forInline, 'target', 'link_open', function (tokens, idx) {
tokens[idx].attrs.push([ 'target', '_blank' ]); tokens[idx].attrs.push([ 'target', '_blank' ]);
}); });

26
test/pathological.js → test/pathological.mjs

@ -1,17 +1,18 @@
'use strict'; import needle from 'needle';
import assert from 'node:assert';
import crypto from 'node:crypto';
const needle = require('needle'); import { Worker as JestWorker } from 'jest-worker';
const assert = require('assert'); import { readFileSync } from 'fs';
const crypto = require('crypto');
const Worker = require('jest-worker').default;
async function test_pattern(str) { async function test_pattern(str) {
const worker = new Worker(require.resolve('./pathological_worker.js'), { const worker = new JestWorker(
numWorkers: 1, new URL('./pathological_worker.js', import.meta.url),
enableWorkerThreads: true {
}); numWorkers: 1,
enableWorkerThreads: true
}
);
let result; let result;
@ -49,10 +50,11 @@ describe('Pathological sequences speed', () => {
/* eslint-disable max-len */ /* eslint-disable max-len */
const src = await needle('get', 'https://raw.githubusercontent.com/commonmark/cmark/master/test/pathological_tests.py'); const src = await needle('get', 'https://raw.githubusercontent.com/commonmark/cmark/master/test/pathological_tests.py');
const src_md5 = crypto.createHash('md5').update(src.body).digest('hex'); const src_md5 = crypto.createHash('md5').update(src.body).digest('hex');
const tracked_md5 = JSON.parse(readFileSync(new URL('./pathological.json', import.meta.url))).md5;
assert.strictEqual( assert.strictEqual(
src_md5, src_md5,
require('./pathological.json').md5, tracked_md5,
'CRC or cmark pathological tests hanged. Verify and update pathological.json' 'CRC or cmark pathological tests hanged. Verify and update pathological.json'
); );
}); });

7
test/ruler.js → test/ruler.mjs

@ -1,8 +1,5 @@
'use strict'; import { assert } from 'chai';
import Ruler from '../lib/ruler.js';
var assert = require('chai').assert;
var Ruler = require('../lib/ruler');
describe('Ruler', function () { describe('Ruler', function () {

6
test/token.js → test/token.mjs

@ -1,7 +1,5 @@
'use strict'; import { assert } from 'chai';
import Token from '../lib/token.js';
var assert = require('chai').assert;
var Token = require('../lib/token');
describe('Token', function () { describe('Token', function () {

22
test/utils.js → test/utils.mjs

@ -1,20 +1,18 @@
'use strict'; import { assert } from 'chai';
import utils from '../lib/common/utils.js';
var assert = require('chai').assert;
describe('Utils', function () { describe('Utils', function () {
it('fromCodePoint', function () { it('fromCodePoint', function () {
var fromCodePoint = require('../lib/common/utils').fromCodePoint; var fromCodePoint = utils.fromCodePoint;
assert.strictEqual(fromCodePoint(0x20), ' '); assert.strictEqual(fromCodePoint(0x20), ' ');
assert.strictEqual(fromCodePoint(0x1F601), '😁'); assert.strictEqual(fromCodePoint(0x1F601), '😁');
}); });
it('isValidEntityCode', function () { it('isValidEntityCode', function () {
var isValidEntityCode = require('../lib/common/utils').isValidEntityCode; var isValidEntityCode = utils.isValidEntityCode;
assert.strictEqual(isValidEntityCode(0x20), true); assert.strictEqual(isValidEntityCode(0x20), true);
assert.strictEqual(isValidEntityCode(0xD800), false); assert.strictEqual(isValidEntityCode(0xD800), false);
@ -28,7 +26,7 @@ describe('Utils', function () {
}); });
/*it('replaceEntities', function () { /*it('replaceEntities', function () {
var replaceEntities = require('../lib/common/utils').replaceEntities; var replaceEntities = utils.replaceEntities;
assert.strictEqual(replaceEntities('&amp;'), '&'); assert.strictEqual(replaceEntities('&amp;'), '&');
assert.strictEqual(replaceEntities('&#32;'), ' '); assert.strictEqual(replaceEntities('&#32;'), ' ');
@ -40,7 +38,7 @@ describe('Utils', function () {
});*/ });*/
it('assign', function () { it('assign', function () {
var assign = require('../lib/common/utils').assign; var assign = utils.assign;
assert.deepEqual(assign({ a: 1 }, null, { b: 2 }), { a: 1, b: 2 }); assert.deepEqual(assign({ a: 1 }, null, { b: 2 }), { a: 1, b: 2 });
assert.throws(function () { assert.throws(function () {
@ -49,13 +47,13 @@ describe('Utils', function () {
}); });
it('escapeRE', function () { it('escapeRE', function () {
var escapeRE = require('../lib/common/utils').escapeRE; var escapeRE = utils.escapeRE;
assert.strictEqual(escapeRE(' .?*+^$[]\\(){}|-'), ' \\.\\?\\*\\+\\^\\$\\[\\]\\\\\\(\\)\\{\\}\\|\\-'); assert.strictEqual(escapeRE(' .?*+^$[]\\(){}|-'), ' \\.\\?\\*\\+\\^\\$\\[\\]\\\\\\(\\)\\{\\}\\|\\-');
}); });
it('isWhiteSpace', function () { it('isWhiteSpace', function () {
var isWhiteSpace = require('../lib/common/utils').isWhiteSpace; var isWhiteSpace = utils.isWhiteSpace;
assert.strictEqual(isWhiteSpace(0x2000), true); assert.strictEqual(isWhiteSpace(0x2000), true);
assert.strictEqual(isWhiteSpace(0x09), true); assert.strictEqual(isWhiteSpace(0x09), true);
@ -64,7 +62,7 @@ describe('Utils', function () {
}); });
it('isMdAsciiPunct', function () { it('isMdAsciiPunct', function () {
var isMdAsciiPunct = require('../lib/common/utils').isMdAsciiPunct; var isMdAsciiPunct = utils.isMdAsciiPunct;
assert.strictEqual(isMdAsciiPunct(0x30), false); assert.strictEqual(isMdAsciiPunct(0x30), false);
@ -74,7 +72,7 @@ describe('Utils', function () {
}); });
it('unescapeMd', function () { it('unescapeMd', function () {
var unescapeMd = require('../lib/common/utils').unescapeMd; var unescapeMd = utils.unescapeMd;
assert.strictEqual(unescapeMd('\\foo'), '\\foo'); assert.strictEqual(unescapeMd('\\foo'), '\\foo');
assert.strictEqual(unescapeMd('foo'), 'foo'); assert.strictEqual(unescapeMd('foo'), 'foo');
Loading…
Cancel
Save