mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
Replace require with import
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import async from 'async'
|
||||
import clone from 'clone'
|
||||
import rimraf from 'rimraf'
|
||||
|
||||
const async = require('async')
|
||||
const clone = require('clone')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const mermaid = require('../lib')
|
||||
import mermaidCli from '../lib'
|
||||
|
||||
const fileTestMermaid = path.join('test', 'fixtures', 'test.mermaid')
|
||||
const isWin = /^win/.test(process.platform)
|
||||
@@ -53,7 +52,7 @@ test('output of single png', function (done) {
|
||||
opt.outputDir += '_png'
|
||||
opt.png = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@@ -70,7 +69,7 @@ test('output of multiple png', function (done) {
|
||||
opt.outputDir += '_png'
|
||||
opt.png = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@@ -86,7 +85,7 @@ test('output of single svg', function (done) {
|
||||
opt.outputDir += '_svg'
|
||||
opt.svg = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@@ -103,7 +102,7 @@ test('output of multiple svg', function (done) {
|
||||
opt.outputDir += '_svg'
|
||||
opt.svg = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@@ -122,14 +121,14 @@ test('output including CSS', function (done) {
|
||||
opt2.png = true
|
||||
opt2.outputDir += '_css_png'
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
const filename = path.join(opt.outputDir, path.basename(expected[0]))
|
||||
const one = fs.statSync(filename)
|
||||
|
||||
opt2.css = path.join('test', 'fixtures', 'test.css')
|
||||
|
||||
mermaid.process(opt2.files, opt2, function (code) {
|
||||
mermaidCli.process(opt2.files, opt2, function (code) {
|
||||
expect(code).toBe(0)
|
||||
const two = fs.statSync(filename)
|
||||
expect(one.size).not.toBe(two.size)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const cliPath = '../lib/cli'
|
||||
import cli from '../lib/cli'
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
|
||||
@@ -9,7 +9,6 @@ beforeEach(() => {
|
||||
test('parses multiple files', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
|
||||
const expected = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
|
||||
|
||||
@@ -25,7 +24,6 @@ test('parses multiple files', function (done) {
|
||||
test('defaults to png', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -40,7 +38,6 @@ test('defaults to png', function (done) {
|
||||
test('setting svg unsets png', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-s']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -55,7 +52,6 @@ test('setting svg unsets png', function (done) {
|
||||
test('setting png and svg is allowed', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-s', '-p']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -70,7 +66,6 @@ test('setting png and svg is allowed', function (done) {
|
||||
test('setting an output directory succeeds', function (done) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-o', 'example/']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -83,7 +78,6 @@ test('setting an output directory succeeds', function (done) {
|
||||
test('not setting a css source file uses a default style', function (done) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -96,7 +90,6 @@ test('not setting a css source file uses a default style', function (done) {
|
||||
test('setting a css source file succeeds', function (done) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@@ -109,7 +102,6 @@ test('setting a css source file succeeds', function (done) {
|
||||
test('setting an output directory incorrectly causes an error', function (done) {
|
||||
expect.assertions(1)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['-o']
|
||||
|
||||
cli.parse(argv, function (err) {
|
||||
@@ -122,7 +114,6 @@ test('setting an output directory incorrectly causes an error', function (done)
|
||||
test('a callback function is called after parsing', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
cli.parse(argv, function (err, msg, opts) {
|
||||
|
@@ -1,14 +1,13 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const exec = require('child_process').exec
|
||||
const path = require('path')
|
||||
|
||||
const rimraf = require('rimraf')
|
||||
import path from 'path'
|
||||
import rimraf from 'rimraf'
|
||||
import { exec } from 'child_process'
|
||||
|
||||
const localSearchPath = './node_modules/.bin' + path.delimiter + process.env.PATH
|
||||
const testDir = 'test/fixtures/samples/'.replace('/', path.sep)
|
||||
const phantomjs = 'node_modules/.bin/phantomjs '.replace('/', path.sep)
|
||||
const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.phantomjs'
|
||||
const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.js'
|
||||
|
||||
rimraf.sync(testDir + '*.actual.*')
|
||||
|
||||
|
16
test/fixtures/samples/load_html_save_screenshot_png.js
vendored
Normal file
16
test/fixtures/samples/load_html_save_screenshot_png.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
// usage: ../../../node_modules/.bin/phantomjs <html> <png>
|
||||
import system from 'system'
|
||||
import webpage from 'webpage'
|
||||
|
||||
const html = system.args[1]
|
||||
const png = system.args[2]
|
||||
console.log('png:', png)
|
||||
|
||||
const page = webpage.create()
|
||||
|
||||
page.open(html)
|
||||
page.onLoadFinished = function () {
|
||||
page.render(png)
|
||||
global.phantom.exit()
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
// usage: ../../../node_modules/.bin/phantomjs <html> <png>
|
||||
var system = require('system');
|
||||
var html = system.args[1];
|
||||
var png = system.args[2];
|
||||
console.log('png:', png)
|
||||
var page = require('webpage').create(),
|
||||
loadInProgress = false,
|
||||
fs = require('fs');
|
||||
|
||||
page.open(html);
|
||||
page.onLoadFinished = function() {
|
||||
loadInProgress = false;
|
||||
page.render(png);
|
||||
phantom.exit();
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "usageTests",
|
||||
"version": "0.4.0",
|
||||
"homepage": "https://github.com/knsv/mermaid",
|
||||
"authors": [
|
||||
"knsv <knut@sveido.com>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"requirejs": "~2.1.16",
|
||||
"mermaid": "~0.4.0",
|
||||
"qunit": "~1.18.0"
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<script src="bower_components/mermaid/dist/mermaid.min.js"></script>
|
||||
<script>
|
||||
var mermaid_config = {
|
||||
startOnLoad:true
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function apa(){
|
||||
console.log('CLICKED');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
TEST 0.2.16
|
||||
<div class="mermaid">
|
||||
graph TD;
|
||||
sq[Square shape2] --> ci((Circle shape // Начало))
|
||||
</div>
|
||||
<h1>Shapes</h1>
|
||||
<div class="mermaid">
|
||||
info
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph LR
|
||||
A[Square Rect] -- Link text --> B((Circle))
|
||||
A --> C(Round Rect)
|
||||
B --> D{Rhombus}
|
||||
C --> D
|
||||
</div>
|
||||
<div class="mermaid">
|
||||
graph TD;
|
||||
sq[Square shape]-->ci((Circle shape));
|
||||
od>Odd shape]---|Two line<br>edge comment|ro;
|
||||
od2>Really long text in an Odd shape]-->od3>Really long text with linebreak<br>in an Odd shape];
|
||||
di{Diamond is <br/> broken}-->ro(Rounded<br>square<br>shape);
|
||||
di-->ro2(Rounded square shape);
|
||||
e((Inner circle URL))-->f(,.?!+-*ز);
|
||||
style e red;
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"gulp": "^3.8.10"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
/* eslint-env qunit */
|
||||
require.config({
|
||||
paths: {
|
||||
mermaid: '../../dist/mermaid'
|
||||
},
|
||||
shim: {
|
||||
mermaid: {
|
||||
exports: 'mermaid'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
require([], function () {
|
||||
QUnit.module('requireTest.html')
|
||||
|
||||
QUnit.test('using mermaid in requirejs', function (assert) {
|
||||
var done = assert.async()
|
||||
require(['mermaid'], function (mermaid) {
|
||||
assert.ok(mermaid, 'mermaid is not null')
|
||||
console.log(mermaid)
|
||||
mermaid.init()
|
||||
assert.equal(window.d3.selectAll('path')[0].length, 8,
|
||||
'drew 8 paths')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.load()
|
||||
QUnit.start()
|
||||
})
|
@@ -1,27 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="bower_components/qunit/qunit/qunit.css" />
|
||||
<link rel="stylesheet" href="../../dist/mermaid.forest.css"/>
|
||||
|
||||
<script src="bower_components/qunit/qunit/qunit.js"></script>
|
||||
<script>
|
||||
QUnit.config.autostart = false;
|
||||
</script>
|
||||
|
||||
<script data-main="reqJsApp.js" src="bower_components/requirejs/require.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<div class="mermaid">
|
||||
graph LR
|
||||
A-->B
|
||||
B-->C
|
||||
C-->A
|
||||
D-->C
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user