greg 4d1d2f8c52
Some checks failed
continuous-integration/drone Build is failing
maj
2023-06-11 20:17:11 +02:00

43 lines
1.1 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import assert from 'assert';
import {parse as babelParse} from '@babel/parser';
import {generateAST} from '../src';
const FIXTURES_FOLDER = path.join(__dirname, 'fixtures');
const files = fs.readdirSync(FIXTURES_FOLDER).sort();
const options = {
allowReturnOutsideFunction: true,
strictMode: false,
sourceType: 'module',
};
describe('astring babel generator', () => {
files.forEach(filename => {
it(filename, function() {
const code = fs.readFileSync(
path.join(FIXTURES_FOLDER, filename),
'utf8',
);
const ast = babelParse(code, options);
let {content} = generateAST({
ast,
sourceFileName: '/foo/bar.js',
sourceMaps: false,
originalSourceMap: null,
options: {projectRoot: '/foo'},
});
if (filename === 'valid-only.js') {
babelParse(content), options;
} else {
assert.equal(
content,
code,
filename.substring(0, filename.length - 3),
'Generates code with the expected format',
);
}
});
});
});