Skip to content

Commit

Permalink
Fully migrate to ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
phanect committed May 10, 2024
1 parent ce5313a commit 38dddf6
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 257 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions lib/esm/package.json

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"version": "4.0.0",
"author": "Matthew Eernisse <matthew.eernisse@gmail.com>",
"license": "Apache-2.0",
"type": "module",
"bin": {
"ejs": "./bin/cli.js"
},
Expand Down Expand Up @@ -47,7 +48,7 @@
"npm": ">=10"
},
"scripts": {
"build": "jake build",
"test": "jake test"
"build": "jake --jakefile=jakefile.cjs build",
"test": "jake --jakefile=jakefile.cjs test"
}
}
52 changes: 26 additions & 26 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let exec = require('child_process').execSync;
let fs = require('fs');
let path = require('path');
let assert = require('assert');
import { execSync as exec } from 'child_process';
import { readFileSync } from 'fs';
import { join } from 'path';
import { equal } from 'assert';
let os = process.platform !== 'win32' ? '' : 'node ';
let lf = process.platform !== 'win32' ? '\n' : '\r\n';

Expand All @@ -11,55 +11,55 @@ function run(cmd) {

suite('cli', function () {
test('rendering, custom delimiter, passed data', function () {
let x = path.join('./bin/cli.js');
let u = path.join('./test/fixtures/user.ejs');
let x = join('./bin/cli.js');
let u = join('./test/fixtures/user.ejs');
let o = run(os+x+' -m $ '+u+' name=foo');
assert.equal(o, '<h1>foo</h1>'+lf);
equal(o, '<h1>foo</h1>'+lf);
});

test('rendering, custom delimiter, data from file with -f', function () {
let x = path.join('./bin/cli.js');
let u = path.join('./test/fixtures/user.ejs');
let x = join('./bin/cli.js');
let u = join('./test/fixtures/user.ejs');
let o = run(os+x+' -m $ -f ./test/fixtures/user_data.json '+u);
assert.equal(o, '<h1>zerb</h1>'+lf);
equal(o, '<h1>zerb</h1>'+lf);
});

test('rendering, custom delimiter, data from CLI arg with -i', function () {
let x = path.join('./bin/cli.js');
let u = path.join('./test/fixtures/user.ejs');
let x = join('./bin/cli.js');
let u = join('./test/fixtures/user.ejs');
let o = run(os+x+' -m $ -i %7B%22name%22%3A%20%22foo%22%7D '+u);
assert.equal(o, '<h1>foo</h1>'+lf);
equal(o, '<h1>foo</h1>'+lf);
});

test('rendering, custom delimiter, data from stdin / pipe', function () {
if ( process.platform !== 'win32' ) {
let o = run('cat ./test/fixtures/user_data.json | ./bin/cli.js -m $ ./test/fixtures/user.ejs');
assert.equal(o, '<h1>zerb</h1>\n');
equal(o, '<h1>zerb</h1>\n');
} // does not work on windows...
});

test('rendering, custom delimiter, passed data overrides file', function () {
let x = path.join('./bin/cli.js');
let f = path.join('./test/fixtures/user_data.json');
let g = path.join('./test/fixtures/user.ejs');
let x = join('./bin/cli.js');
let f = join('./test/fixtures/user_data.json');
let g = join('./test/fixtures/user.ejs');
let o = run(os+x+' -m $ -f '+f+' '+g+' name=frang');
assert.equal(o, '<h1>frang</h1>'+lf);
equal(o, '<h1>frang</h1>'+lf);
});

test('rendering, remove whitespace option (hyphen case)', function () {
let x = path.join('./bin/cli.js');
let f = path.join('./test/fixtures/rmWhitespace.ejs');
let x = join('./bin/cli.js');
let f = join('./test/fixtures/rmWhitespace.ejs');
let o = run(os+x+' --rm-whitespace '+f);
let c = fs.readFileSync('test/fixtures/rmWhitespace.html', 'utf-8');
assert.equal(o.replace(/\n/g, lf), c);
let c = readFileSync('test/fixtures/rmWhitespace.html', 'utf-8');
equal(o.replace(/\n/g, lf), c);
});

test('relative path in nested include', function () {
let x = path.join('./bin/cli.js');
let u = path.join('test/fixtures/include-simple.ejs');
let x = join('./bin/cli.js');
let u = join('test/fixtures/include-simple.ejs');
let o = run(os+x+' '+u);
let c = fs.readFileSync('test/fixtures/include-simple.html', 'utf-8');
assert.equal(o, c);
let c = readFileSync('test/fixtures/include-simple.html', 'utf-8');
equal(o, c);
});

});
Loading

0 comments on commit 38dddf6

Please sign in to comment.