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. 22
      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:
node: true
browser: false
es6: false
overrides:
-
files: [ '*.mjs' ]
parserOptions:
sourceType: module
ignorePatterns:
- coverage/

4
package.json

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

3
test/.eslintrc.yml

@ -1,7 +1,6 @@
env:
node: true
mocha: true
es6: true
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 () {
var app;
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) {
return new Promise(resolve => setTimeout(resolve, ms));
}
before(async () => {
app = require('child_process').execFile(
app = execFile(
'node',
[ '../support/babelmark-responder.js' ],
{
cwd: __dirname,
cwd: new URL('.', import.meta.url),
env: Object.assign({}, process.env, { PORT: PORT })
}
);
@ -41,13 +43,15 @@ describe('babelmark responder app', function () {
it('do request', () => {
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version;
return request
.get('/?text=foo')
.expect(200)
.expect({
html: '<p>foo</p>\n',
name: 'markdown-it',
version: require('../package.json').version
version
});
});

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

@ -1,9 +1,8 @@
'use strict';
var p = require('path');
var load = require('markdown-it-testgen').load;
var assert = require('chai').assert;
import { fileURLToPath } from 'node:url';
import { relative } from 'node:path';
import { load } from 'markdown-it-testgen';
import markdownit from '../index.js';
import { assert } from 'chai';
function normalize(text) {
@ -15,7 +14,7 @@ function generate(path, md) {
load(path, function (data) {
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.fixtures.forEach(function (fixture) {
@ -29,7 +28,7 @@ function generate(path, md) {
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';
var assert = require('chai').assert;
var markdownit = require('../');
import { assert } from 'chai';
import markdownit from '../index.js';
import forInline from 'markdown-it-for-inline';
describe('API', function () {
@ -269,7 +267,7 @@ describe('Misc', function () {
it('Should render link target attr', function () {
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' ]);
});

22
test/pathological.js → test/pathological.mjs

@ -1,17 +1,18 @@
'use strict';
const needle = require('needle');
const assert = require('assert');
const crypto = require('crypto');
const Worker = require('jest-worker').default;
import needle from 'needle';
import assert from 'node:assert';
import crypto from 'node:crypto';
import { Worker as JestWorker } from 'jest-worker';
import { readFileSync } from 'fs';
async function test_pattern(str) {
const worker = new Worker(require.resolve('./pathological_worker.js'), {
const worker = new JestWorker(
new URL('./pathological_worker.js', import.meta.url),
{
numWorkers: 1,
enableWorkerThreads: true
});
}
);
let result;
@ -49,10 +50,11 @@ describe('Pathological sequences speed', () => {
/* eslint-disable max-len */
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 tracked_md5 = JSON.parse(readFileSync(new URL('./pathological.json', import.meta.url))).md5;
assert.strictEqual(
src_md5,
require('./pathological.json').md5,
tracked_md5,
'CRC or cmark pathological tests hanged. Verify and update pathological.json'
);
});

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

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

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

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

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

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