test: add UMD module test with marked
PR-URL: https://github.com/nodejs/node/pull/38905 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
3611045dfc
commit
a63af1fd64
21
test/fixtures/snapshot/check-marked.js
vendored
Normal file
21
test/fixtures/snapshot/check-marked.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
let marked;
|
||||||
|
if (process.env.NODE_TEST_USE_SNAPSHOT === 'true') {
|
||||||
|
console.error('NODE_TEST_USE_SNAPSHOT true');
|
||||||
|
marked = globalThis.marked;
|
||||||
|
} else {
|
||||||
|
console.error('NODE_TEST_USE_SNAPSHOT false');
|
||||||
|
marked = require('./marked');
|
||||||
|
}
|
||||||
|
|
||||||
|
const md = `
|
||||||
|
# heading
|
||||||
|
|
||||||
|
[link][1]
|
||||||
|
|
||||||
|
[1]: #heading "heading"
|
||||||
|
`;
|
||||||
|
|
||||||
|
const html = marked(md)
|
||||||
|
console.log(html);
|
2970
test/fixtures/snapshot/marked.js
vendored
Normal file
2970
test/fixtures/snapshot/marked.js
vendored
Normal file
File diff suppressed because one or more lines are too long
77
test/parallel/test-snapshot-umd.js
Normal file
77
test/parallel/test-snapshot-umd.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This tests the behavior of loading a UMD module with --build-snapshot
|
||||||
|
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
const fixtures = require('../common/fixtures');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
tmpdir.refresh();
|
||||||
|
const blobPath = path.join(tmpdir.path, 'snapshot.blob');
|
||||||
|
const file = fixtures.path('snapshot', 'marked.js');
|
||||||
|
|
||||||
|
{
|
||||||
|
// By default, the snapshot blob path is snapshot.blob at cwd
|
||||||
|
const child = spawnSync(process.execPath, [
|
||||||
|
'--snapshot-blob',
|
||||||
|
blobPath,
|
||||||
|
'--build-snapshot',
|
||||||
|
file,
|
||||||
|
], {
|
||||||
|
cwd: tmpdir.path
|
||||||
|
});
|
||||||
|
const stderr = child.stderr.toString();
|
||||||
|
const stdout = child.stdout.toString();
|
||||||
|
console.log(stderr);
|
||||||
|
console.log(stdout);
|
||||||
|
assert.strictEqual(child.status, 0);
|
||||||
|
|
||||||
|
const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob'));
|
||||||
|
assert(stats.isFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let child = spawnSync(process.execPath, [
|
||||||
|
'--snapshot-blob',
|
||||||
|
path.join(tmpdir.path, 'snapshot.blob'),
|
||||||
|
fixtures.path('snapshot', 'check-marked.js'),
|
||||||
|
], {
|
||||||
|
cwd: tmpdir.path,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
NODE_TEST_USE_SNAPSHOT: 'true'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let stderr = child.stderr.toString();
|
||||||
|
const snapshotOutput = child.stdout.toString();
|
||||||
|
console.log(stderr);
|
||||||
|
console.log(snapshotOutput);
|
||||||
|
|
||||||
|
assert.strictEqual(child.status, 0);
|
||||||
|
assert(stderr.includes('NODE_TEST_USE_SNAPSHOT true'));
|
||||||
|
|
||||||
|
child = spawnSync(process.execPath, [
|
||||||
|
'--snapshot-blob',
|
||||||
|
blobPath,
|
||||||
|
fixtures.path('snapshot', 'check-marked.js'),
|
||||||
|
], {
|
||||||
|
cwd: tmpdir.path,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
NODE_TEST_USE_SNAPSHOT: 'false'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stderr = child.stderr.toString();
|
||||||
|
const verifyOutput = child.stdout.toString();
|
||||||
|
console.log(stderr);
|
||||||
|
console.log(verifyOutput);
|
||||||
|
|
||||||
|
assert.strictEqual(child.status, 0);
|
||||||
|
assert(stderr.includes('NODE_TEST_USE_SNAPSHOT false'));
|
||||||
|
|
||||||
|
assert(snapshotOutput.includes(verifyOutput));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user