This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+62
View File
@@ -0,0 +1,62 @@
/*jshint node:true */
var requirejs = require('requirejs'),
SanityTest = require('./sanitytest'),
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
run_javascript_tests = require('./generated/beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./generated/beautify-css-tests').run_css_tests,
run_html_tests = require('./generated/beautify-html-tests').run_html_tests;
requirejs.config({
paths: {
'beautify': "..",
'beautify-lib': "../lib"
}
});
function amd_beautifier_index_tests(name, test_runner) {
console.log('Testing ' + name + ' with node.js Require.js (index file)...');
var results = new SanityTest();
var beautify = requirejs('beautify/index');
test_runner(
results,
Urlencoded,
beautify.js,
beautify.html,
beautify.css);
console.log(results.results_raw());
return results;
}
function amd_beautifier_tests(name, test_runner) {
console.log('Testing ' + name + ' with node.js Require.js (separate file)...');
var results = new SanityTest();
var js_beautify = requirejs('beautify-lib/beautify'),
css_beautify = requirejs('beautify-lib/beautify-css'),
html_beautify = requirejs('beautify-lib/beautify-html');
test_runner(
results,
Urlencoded,
js_beautify.js_beautify,
html_beautify.html_beautify,
css_beautify.css_beautify);
console.log(results.results_raw());
return results;
}
if (require.main === module) {
process.exit(
amd_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() +
amd_beautifier_index_tests('js-beautifier', run_javascript_tests).get_exitcode() +
amd_beautifier_tests('cs-beautifier', run_css_tests).get_exitcode() +
amd_beautifier_index_tests('css-beautifier', run_css_tests).get_exitcode() +
amd_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() +
amd_beautifier_index_tests('html-beautifier', run_html_tests).get_exitcode()
);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+51
View File
@@ -0,0 +1,51 @@
/*global js_beautify: true */
/*jshint node:true */
/*jshint unused:false */
var fs = require('fs'),
SanityTest = require('./sanitytest'),
Benchmark = require('benchmark'),
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
js_beautify = require('../index').js_beautify,
css_beautify = require('../index').css_beautify,
html_beautify = require('../index').html_beautify;
function node_beautifier_html_tests() {
console.log('Testing performance...');
var index_html = fs.readFileSync(__dirname + '/../../index.html', 'utf8');
var data_attr = fs.readFileSync(__dirname + '/../../test/resources/html-with-base64image.html', 'utf8');
var options = {
wrap_line_length: 80
};
//warm-up
html_beautify(index_html, options);
html_beautify(data_attr, options);
var suite = new Benchmark.Suite();
suite.add("html-beautify (index.html)", function() {
html_beautify(index_html, options);
})
.add("html-beautify (base64 image)", function() {
html_beautify(data_attr, options);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('error', function(event) {
return 1;
})
.on('complete', function(event) {})
.run();
return 0;
}
if (require.main === module) {
process.exit(node_beautifier_html_tests());
}
+50
View File
@@ -0,0 +1,50 @@
/*global js_beautify: true */
/*jshint node:true */
/*jshint unused:false */
var fs = require('fs'),
SanityTest = require('./sanitytest'),
Benchmark = require('benchmark'),
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
js_beautify = require('../index').js_beautify,
css_beautify = require('../index').css_beautify,
html_beautify = require('../index').html_beautify;
function node_beautifier_tests() {
console.log('Testing performance...');
var data = fs.readFileSync(__dirname + '/../../test/resources/underscore.js', 'utf8');
var data_min = fs.readFileSync(__dirname + '/../../test/resources/underscore-min.js', 'utf8');
var options = {
wrap_line_length: 80
};
//warm-up
js_beautify(data, options);
js_beautify(data_min, options);
var suite = new Benchmark.Suite();
suite.add("js-beautify (underscore)", function() {
js_beautify(data, options);
})
.add("js-beautify (underscore-min)", function() {
js_beautify(data_min, options);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('error', function(event) {
return 1;
})
.on('complete', function(event) {})
.run();
return 0;
}
if (require.main === module) {
process.exit(node_beautifier_tests());
}
+45
View File
@@ -0,0 +1,45 @@
/*jshint node:true */
var SanityTest = require('./sanitytest'),
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
run_javascript_tests = require('./generated/beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./generated/beautify-css-tests').run_css_tests,
run_html_tests = require('./generated/beautify-html-tests').run_html_tests;
function test_legacy_names() {
var beautify = require('../index');
var results = new SanityTest();
console.log('First ensure that legacy import names equal the new ones');
results.expect(beautify.js, beautify.js_beautify);
results.expect(beautify.css, beautify.css_beautify);
results.expect(beautify.html, beautify.html_beautify);
console.log(results.results_raw());
return results;
}
function node_beautifier_tests(name, test_runner) {
console.log('Testing ' + name + ' with node.js CommonJS...');
var beautify = require('../index');
var results = new SanityTest();
test_runner(
results,
Urlencoded,
beautify.js,
beautify.html,
beautify.css);
console.log(results.results_raw());
return results;
}
if (require.main === module) {
process.exit(
test_legacy_names() +
node_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() +
node_beautifier_tests('css-beautifier', run_css_tests).get_exitcode() +
node_beautifier_tests('html-beautifier', run_html_tests).get_exitcode()
);
}
+58
View File
@@ -0,0 +1,58 @@
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script type="text/javascript">
require(["../lib/beautify-html"],function(html_beautify){
var input = document.getElementById("input").value;
var output = html_beautify.html_beautify(input);
document.getElementById("output").innerHTML = output;
});
</script>
<style type="text/css">
#output{
border: 1px solid black;
height: 300px;
width: 100%;
}
#input{
width: 100%;
height: 300px;
}
</style>
</head>
<body>
<h1>RequireJS test</h1>
<p>
This example loads the html-beautifier by using a relative path in the require call to the beautify-html.js file.
(also works works with absolute paths)
</p>
<pre>
require(["../lib/beautify-html"],function(html_beautify){
var input = document.getElementById("input").value;
var output = html_beautify.html_beautify(input);
document.getElementById("output").innerHTML = output;
});
</pre>
<h2>Input</h2>
<textarea name="" id="input">
<ul><li><a href="test"></a></li></ul>
</textarea>
<h2>Output</h2>
<textarea name="" id="output">
</textarea>
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
{
"indent_size": 11,
"indent_char": " "
"indent_level": 0,
"indent_with_tabs": false
}
@@ -0,0 +1,6 @@
root = true
[*.js]
indent_style = space
indent_size = 2
insert_final_newline = false
@@ -0,0 +1,3 @@
[*.js]
end_of_line = cr
@@ -0,0 +1,3 @@
[*.js]
end_of_line = crlf
@@ -0,0 +1 @@
Random stuff in here to cause parse error
@@ -0,0 +1,3 @@
function indentMe() {
"no, me!"; // indent_size 4, will be beautified to 2 with editorconfig
}
+3
View File
@@ -0,0 +1,3 @@
function indentMe() {
"no, me!";
}
@@ -0,0 +1,6 @@
{
"indent_size": 11,
"indent_char": " ",
"indent_level": 0,
"indent_with_tabs": false
}
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/spidermonkey-1.7 -s
//#!/usr/bin/js
// a little helper for testing from command line
// just run it, it will output the test results
load('js/lib/beautify.js');
load('js/test/sanitytest.js')
load('js/test/beautify-tests.js')
load('js/lib/unpackers/urlencode_unpacker.js')
print(run_beautifier_tests(new SanityTest(), Urlencoded, js_beautify).results_raw())
// for nodejs use this from the command line from the main directory:
// node test/beautify-tests.js
+144
View File
@@ -0,0 +1,144 @@
//
// simple testing interface
// written by Einar Lielmanis, einar@jsbeautifier.org
//
// usage:
//
// var t = new SanityTest(function (x) { return x; }, 'my function');
// t.expect('input', 'output');
// t.expect('a', 'a');
// output_somewhere(t.results()); // good for <pre>, html safe-ish
// alert(t.results_raw()); // html unescaped
function SanityTest(func, name_of_test) {
var test_func = func || function(x) {
return x;
};
var test_name = name_of_test || '';
var n_failed = 0;
var n_succeeded = 0;
var failures = [];
this.test_function = function(func, name) {
test_func = func;
test_name = name || '';
};
this.get_exitcode = function() {
return n_succeeded === 0 || n_failed !== 0 ? 1 : 0;
};
this.expect = function(parameters, expected_value) {
// multi-parameter calls not supported (I don't need them now).
var result = test_func(parameters);
// proper array checking is a pain. i'll maybe do it later, compare strings representations instead
if ((result === expected_value) || (expected_value instanceof Array && result.join(', ') === expected_value.join(', '))) {
n_succeeded += 1;
} else {
n_failed += 1;
failures.push([test_name, parameters, expected_value, result]);
}
};
this.results_raw = function() {
var results = '';
if (n_failed === 0) {
if (n_succeeded === 0) {
results = 'No tests run.';
} else {
results = 'All ' + n_succeeded + ' tests passed.';
}
} else {
for (var i = 0; i < failures.length; i++) {
var f = failures[i];
if (f[0]) {
f[0] = f[0] + ' ';
}
results += '==== ' + f[0] + '============================================================\n';
results += '---- input -------\n' + this.prettyprint(f[1]) + '\n';
results += '---- expected ----\n' + this.prettyprint(f[2]) + '\n';
results += '---- output ------\n' + this.prettyprint(f[3]) + '\n';
results += '---- expected-ws ------\n' + this.prettyprint_whitespace(f[2]) + '\n';
results += '---- output-ws ------\n' + this.prettyprint_whitespace(f[3]) + '\n';
results += '================================================================\n\n';
}
results += n_failed + ' tests failed.\n';
}
return results;
};
this.results = function() {
return this.lazy_escape(this.results_raw());
};
this.prettyprint_whitespace = function(something, quote_strings) {
return (this.prettyprint(something, quote_strings)
.replace(/\r\n/g, '\\r\n')
.replace(/\n/g, '\\n\n')
.replace(/\r/g, '\\r\n')
.replace(/ /g, '_')
.replace(/\t/g, '===|'));
};
this.prettyprint = function(something, quote_strings) {
var type = typeof something;
switch (type.toLowerCase()) {
case 'string':
if (quote_strings) {
return "'" + something.replace("'", "\\'") + "'";
}
return something;
case 'number':
return '' + something;
case 'boolean':
return something ? 'true' : 'false';
case 'undefined':
return 'undefined';
case 'object':
if (something instanceof Array) {
var x = [];
var expected_index = 0;
for (var k in something) {
if (k === expected_index) {
x.push(this.prettyprint(something[k], true));
expected_index += 1;
} else {
x.push('\n' + k + ': ' + this.prettyprint(something[k], true));
}
}
return '[' + x.join(', ') + ']';
}
return 'object: ' + something;
default:
return type + ': ' + something;
}
};
this.lazy_escape = function(str) {
return str.replace(/</g, '&lt;').replace(/\>/g, '&gt;').replace(/\n/g, '<br />');
};
this.log = function() {
if (window.console) {
if (console.firebug) {
console.log.apply(console, Array.prototype.slice.call(arguments));
} else {
console.log.call(console, Array.prototype.slice.call(arguments));
}
}
};
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = SanityTest;
}
+383
View File
@@ -0,0 +1,383 @@
#!/usr/bin/env bash
REL_SCRIPT_DIR="`dirname \"$0\"`"
SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
test_cli_common()
{
echo ----------------------------------------
echo Testing common cli behavior...
CLI_SCRIPT_NAME=${1:?missing_param}.js
CLI_SCRIPT=$SCRIPT_DIR/../bin/$CLI_SCRIPT_NAME
echo Script: $CLI_SCRIPT
# should find the minimal help output
$CLI_SCRIPT 2>&1 | grep -q "Must pipe input or define at least one file\." || {
$CLI_SCRIPT 2>&1
echo "[$CLI_SCRIPT_NAME] Output should be help message."
exit 1
}
$CLI_SCRIPT 2> /dev/null && {
echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error."
exit 1
}
$CLI_SCRIPT -Z 2> /dev/null && {
echo "[$CLI_SCRIPT_NAME -Z] Return code for invalid parameter should be error."
exit 1
}
$CLI_SCRIPT -h > /dev/null || {
echo "[$CLI_SCRIPT_NAME -h] Return code should be success."
exit 1
}
$CLI_SCRIPT -v > /dev/null || {
echo "[$CLI_SCRIPT_NAME -v] Return code should be success."
exit 1
}
MISSING_FILE="$SCRIPT_DIR/../../../js/bin/missing_file"
MISSING_FILE_MESSAGE="Unable to open path"
$CLI_SCRIPT $MISSING_FILE 2> /dev/null && {
echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Return code should be error."
exit 1
}
$CLI_SCRIPT $MISSING_FILE 2>&1 | grep -q "$MISSING_FILE_MESSAGE" || {
echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stderr should have useful message."
exit 1
}
if [ "`$CLI_SCRIPT $MISSING_FILE 2> /dev/null`" != "" ]; then
echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stdout should have no text."
exit 1
fi
}
setup_temp()
{
mkdir -p target
TEST_TEMP=$PWD/`mktemp -d target/test_temp_XXXX`
echo Created $TEST_TEMP...
}
cleanup()
{
rm -rf $TEST_TEMP && echo Removed $TEST_TEMP...
test -z $1 || exit $1
}
test_cli_js_beautify()
{
echo ----------------------------------------
echo Testing js-beautify cli behavior...
CLI_SCRIPT=$SCRIPT_DIR/../bin/js-beautify.js
$CLI_SCRIPT $SCRIPT_DIR/../bin/js-beautify.js > /dev/null || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected succeed."
exit 1
}
$CLI_SCRIPT $SCRIPT_DIR/../bin/css-beautify.js > /dev/null || {
echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected succeed."
exit 1
}
$CLI_SCRIPT $SCRIPT_DIR/../bin/js-beautify.js | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
exit 1
}
node $SCRIPT_DIR/../lib/cli.js $SCRIPT_DIR/../bin/js-beautify.js | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
exit 1
}
cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
exit 1
}
cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT - | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
exit 1
}
setup_temp
cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT -o $TEST_TEMP/js-beautify-pipe.js - && diff $TEST_TEMP/js-beautify-pipe.js $SCRIPT_DIR/../bin/js-beautify.js || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify-pipe.js."
cleanup 1
}
$CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../bin/js-beautify.js && diff $SCRIPT_DIR/../bin/js-beautify.js $TEST_TEMP/js-beautify.js || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify.js."
cleanup 1
}
# ensure new line settings work
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-n.js -e '\n' $SCRIPT_DIR/../bin/js-beautify.js
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn.js -e '\r\n' $TEST_TEMP/js-beautify-n.js
# ensure eol processed correctly
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-n-dash.js --indent-size 2 --eol '\n' $TEST_TEMP/js-beautify-n.js
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn-dash.js --indent-size 2 --eol '\r\n' $TEST_TEMP/js-beautify-n.js
diff -q $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js && {
diff $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js | cat -t -e
echo "js-beautify output for $TEST_TEMP/js-beautify-n-dash.js and $TEST_TEMP/js-beautify-rn-dash.js was expected to be different."
cleanup 1
}
diff -q $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js && {
diff $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js | cat -t -e
echo "js-beautify output for $TEST_TEMP/js-beautify-n.js and $TEST_TEMP/js-beautify-rn.js was expected to be different."
cleanup 1
}
$CLI_SCRIPT $TEST_TEMP/js-beautify-n.js | diff -q $TEST_TEMP/js-beautify-n.js - || {
echo "js-beautify output for $TEST_TEMP/js-beautify-n.js was expected to be unchanged."
cleanup 1
}
$CLI_SCRIPT -e 'auto' $TEST_TEMP/js-beautify-rn.js | diff -q $TEST_TEMP/js-beautify-rn.js - || {
echo "js-beautify output for $TEST_TEMP/js-beautify-rn.js was expected to be unchanged."
cleanup 1
}
# EditorConfig related tests
cp -r js/test/resources/editorconfig $TEST_TEMP/
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/example-ec.js --indent-size 2 -e '\n' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/cr/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/cr/example-ec.js --indent-size 2 -e '\r' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/crlf/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/crlf/example-ec.js --indent-size 2 -e '\r\n' $TEST_TEMP/editorconfig/example-base.js
$CLI_SCRIPT -o $TEST_TEMP/editorconfig/error/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
pushd $TEST_TEMP/editorconfig
cd $TEST_TEMP/editorconfig/error
$CLI_SCRIPT --editorconfig $TEST_TEMP/js-beautify-n.js \
> /dev/null || {
echo "Invalid editorconfig file should not report error (consistent with the EditorConfig)."
cleanup 1
}
$CLI_SCRIPT --editorconfig example.js \
> /dev/null || {
echo "Invalid editorconfig file should not report error (consistent with the EditorConfig)."
cleanup 1
}
# TODO: EditorConfig setting should NOT overide cli setting, but that is
# the current by-design behavior, due to code limitations.
# file input scenario
SCENARIO=a
cd $TEST_TEMP/editorconfig || exit 1
$CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/crlf || exit 1
$CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/cr || exit 1
$CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
# stdin input to stdout scenario
SCENARIO=b
cd $TEST_TEMP/editorconfig || exit 1
echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/crlf || exit 1
echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/cr || exit 1
echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
# stdin input to file scenario
SCENARIO=c
cd $TEST_TEMP/editorconfig || exit 1
echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js"
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/crlf || exit 1
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
cd $TEST_TEMP/editorconfig/cr || exit 1
cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
&& diff -q example-${SCENARIO}.js example-ec.js || {
echo "EditorConfig setting should overide cli setting."
diff example-${SCENARIO}.js example-ec.js | cat -t -e
cleanup 1
}
popd
# End EditorConfig
# ensure unchanged files are not overwritten
$CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../bin/js-beautify.js
cp -p $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify-old.js
touch $TEST_TEMP/js-beautify.js
sleep 2
touch $TEST_TEMP/js-beautify-old.js
$CLI_SCRIPT -r $TEST_TEMP/js-beautify.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -r"
cleanup 1
}
$CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -o and same file name"
cleanup 1
}
$CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify-old.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -o and different file name"
cleanup 1
}
$CLI_SCRIPT $SCRIPT_DIR/../bin/css-beautify.js | diff -q $SCRIPT_DIR/../bin/css-beautify.js - && {
echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected to be different."
cleanup 1
}
unset HOME
unset USERPROFILE
$CLI_SCRIPT -o $TEST_TEMP/example1-default.js $SCRIPT_DIR/resources/example1.js || exit 1
$CLI_SCRIPT -o $TEST_TEMP/example1-sanity.js $TEST_TEMP/example1-default.js || exit 1
diff -q $TEST_TEMP/example1-default.js $TEST_TEMP/example1-sanity.js || {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be identical after no change in settings."
cleanup 1
}
cd $SCRIPT_DIR/resources/configerror
$CLI_SCRIPT $TEST_TEMP/example1-default.js 2>&1 | grep -q "Error while loading beautifier configuration\." || {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be configration load error message."
cleanup 1
}
cd $SCRIPT_DIR/resources/indent11chars
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD settings."
cleanup 1
}
cd $SCRIPT_DIR/resources/indent11chars/subDir1/subDir2
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD parent folder settings."
cleanup 1
}
cd $SCRIPT_DIR
export HOME=$SCRIPT_DIR/resources/indent11chars
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on HOME settings."
cleanup 1
}
$CLI_SCRIPT -o $TEST_TEMP/example1-indent11chars.js $TEST_TEMP/example1-default.js
unset HOME
export USERPROFILE=$SCRIPT_DIR/resources/indent11chars
# node -p 'process.env["USERPROFILE"] || process.env["HOME"] || "unset"'
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-indent11chars.js - || {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be identical for same HOME and USERPROFILE settings."
cleanup 1
}
$CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on USERPROFILE settings."
cleanup 1
}
cleanup
}
test_smoke_js_beautify()
{
echo ----------------------------------------
echo Testing js-beautify functionality...
node $SCRIPT_DIR/node-beautify-tests.js || exit 1
node $SCRIPT_DIR/amd-beautify-tests.js || exit 1
}
test_performance_js_beautify()
{
echo ----------------------------------------
echo Testing js-beautify performance...
node $SCRIPT_DIR/node-beautify-perf-tests.js || exit 1
echo ----------------------------------------
}
test_performance_html_beautify()
{
echo ----------------------------------------
echo Testing html-beautify performance...
node $SCRIPT_DIR/node-beautify-html-perf-tests.js || exit 1
echo ----------------------------------------
}
test_cli_common css-beautify
test_cli_common html-beautify
test_cli_common js-beautify
test_cli_js_beautify
test_smoke_js_beautify
test_performance_js_beautify
test_performance_html_beautify
echo ----------------------------------------
echo $0 - PASSED.
echo ----------------------------------------