update formatter tests
MODIFY
packages/@romejs/core/test-worker/TestAPI.ts
packages/@romejs/core/test-worker/TestAPI.ts
@@ -518,6 +518,10 @@ export default class TestAPI implements TestHelper {
formatted = prettyFormat(expected);
}
+ if (entryName.toLocaleLowerCase().includes('javascript')) {
+ language = 'javascript';
+ }
+
let snapshotPath = undefined;
if (optionalFilename !== undefined) {
optionalFilename = this._normalizeSnapshotFilename(optionalFilename);

MODIFY
packages/@romejs/js-formatter/index.test.ts
packages/@romejs/js-formatter/index.test.ts
-import {createFixtureTests} from '@romejs/test';
-import {formatJS, BuilderOptions} from '.';
+import {createFixtureTests} from '@romejs/test-helpers';
import {parseJS} from '@romejs/js-parser';
import {ConstProgramSyntax} from '@romejs/js-ast';
-import {writeFileSync} from '@romejs/fs';
+import { removeCarriageReturn } from '@romejs/string-utils';
+import { BuilderOptions, formatJS } from '.';
const promise = createFixtureTests(
- (fixture, t) => {
+ async(fixture, t) => {
const {options, files} = fixture;
+ // Get the input JS
const inputFile = files.get('input.js') || files.get('input.mjs') ||
files.get('input.ts') || files.get('input.tsx');
if (inputFile === undefined) {
@@ -14,22 +15,18 @@ const promise = createFixtureTests(
`The fixture ${fixture.dir} did not have an input.(mjs|js|ts|tsx)`,
);
}
- const filename = inputFile.relative;
- const extension = filename.join().slice(filename.join().lastIndexOf('.'));
- const outputFileName = `output${extension}`;
-
- const outputFile = files.get(outputFileName);
-
- let outputContent = undefined;
- if (outputFile !== undefined) {
- outputContent = outputFile.content.toString().replace(/\r/g, '');
- }
const sourceTypeProp = options.get('sourceType');
const sourceType = sourceTypeProp.asString('script');
if (sourceType !== 'module' && sourceType !== 'script') {
- throw sourceTypeProp.unexpected('Expected either script or module');
+ throw sourceTypeProp.unexpected();
}
+
+ const allowReturnOutsideFunction = options.get('allowReturnOutsideFunction').asBoolean(
+ false,
+ );
+ const filename = inputFile.relative;
+
const syntax: Array<ConstProgramSyntax> = options.get('syntax').asArray(true).map(
(
item,
@@ -37,22 +34,17 @@ const promise = createFixtureTests(
return item.asStringSet(['jsx', 'ts', 'flow']);
},
);
- const allowReturnOutsideFunction = options.get('allowReturnOutsideFunction').asBoolean(
- false,
- );
const format = options.get('format').asStringOrVoid();
- const updateSnapshots = t.options.updateSnapshots;
-
- const inputContent = inputFile.content.toString().replace(/\r/g, '');
+ const inputContent = removeCarriageReturn(inputFile.content.toString());
const ast = parseJS({
input: inputContent,
- sourceType,
path: filename,
- syntax,
allowReturnOutsideFunction,
+ sourceType,
+ syntax,
});
const formatOptions: BuilderOptions = {
@@ -63,8 +55,6 @@ const promise = createFixtureTests(
sourceMaps: false,
};
- const printer = formatJS(ast, formatOptions);
-
t.addToAdvice({
type: 'log',
category: 'info',
@@ -78,11 +68,13 @@ const promise = createFixtureTests(
},
});
- if (outputContent !== undefined && !updateSnapshots) {
- t.is(printer.getCode(), outputContent);
- } else {
- writeFileSync(fixture.dir.append(outputFileName), printer.getCode());
- }
+ const printer = formatJS(ast, formatOptions);
+
+ const outputFile = inputFile.absolute.getParent().append(
+ `${inputFile.absolute.getExtensionlessBasename()}.test.md`,
+ ).join();
+ await t.snapshotNamed('Javascript Input', inputContent, undefined, outputFile);
+ await t.snapshotNamed('Javascript Output', printer.getCode(), undefined, outputFile);
},
);

DELETE
packages/@romejs/js-formatter/test-fixtures/arrays/array-spread/output.js
-let a = [...a, ...b];
-let b = [...a, ...b];

DELETE
packages/@romejs/js-formatter/test-fixtures/arrays/empty-lines/output.js
-let a = [
- 1,
- 2,
-
- 3,
-
- 4,
-];

DELETE
packages/@romejs/js-formatter/test-fixtures/arrays/nested/output.js
-let a = [[]];
-let b = [[], []];
-let c = [[], [], []];
-let d = [[], [0], []];
-let e = [[], [0], [0]];
-let f = [[], [0, 1], [0]];
-let g = [[], [0, 1], [0, 1]];
-let h = [[0]];
-let i = [[0], []];
-let j = [[0], [], []];
-let k = [[0], [0], []];
-let l = [[0], [0], [0]];
-let m = [[0], [0, 1], [0]];
-let n = [[0], [0, 1], [0, 1]];
-let o = [[0, 1]];
-let p = [[0, 1], []];
-let q = [[0, 1], [], []];
-let r = [[0, 1], [0], []];
-let s = [[0, 1], [0], [0]];
-let t = [[0, 1], [0, 1], [0]];
-let u = [[0, 1], [0, 1], [0, 1]];
-let v = [[], [1, 2, 3]];
-let w = [[1], [1]];
-let x = [[1, 2], [1, 2, 3]];
-let y = [[1, 0], [1, 0]];
-let z = [{}];
-let a1 = [{}, {}];
-let b1 = [{}, {}, {}];
-let c1 = [{}, {a}];
-let d1 = [{}, {a, b}];
-let e1 = [{}, {a, b, c}];
-let f1 = [{a}];
-let g1 = [{a}, {a}];
-let h1 = [{a}, {a}, {a}];
-let i1 = [{a}, {a, b}];
-let j1 = [{a}, {a, b, c}];
-let k1 = [{a, b}];
-let l1 = [{a, b}, {a}];
-let m1 = [{a, b}, {a}, {a}];
-let n1 = [{a, b}, {a, b}];
-let o1 = [{a, b}, {a, b, c}];

DELETE
packages/@romejs/js-formatter/test-fixtures/arrays/spaces/output.js
-let a = [];
-let b = [, ];
-let c = [, , 1];
-let d = [, , 1, 1];

DELETE
packages/@romejs/js-formatter/test-fixtures/arrow/arrow-call/output.js
-const testResults = results.testResults.map((testResult) => formatResult(testResult, formatter, reporter));
-
-it('mocks regexp instances', () => {
- expect(() => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/))).not.toThrow();
-});
-
-expect(() => asyncRequest({url: '/test-endpoint'})).toThrowError(/Required parameter/);
-
-expect(() => asyncRequest({url: '/test-endpoint-but-with-a-long-url'})).toThrowError(/Required parameter/);
-
-expect(() => asyncRequest({url: '/test-endpoint-but-with-a-suuuuuuuuper-long-url'})).toThrowError(/Required parameter/);
-
-expect(() => asyncRequest({type: 'foo', url: '/test-endpoint'})).not.toThrowError();
-
-expect(() => asyncRequest({type: 'foo', url: '/test-endpoint-but-with-a-long-url'})).not.toThrowError();
-
-const a = Observable.fromPromise(axiosInstance.post('/carts/mine')).map((response) => response.data);
-
-const b = Observable.fromPromise(axiosInstance.get(url)).map((response) => response.data);
-
-func(veryLoooooooooooooooooooooooongName, (veryLooooooooooooooooooooooooongName) => veryLoooooooooooooooongName.something());
-
-const composition = (ViewComponent, ContainerComponent) => class extends React.Component {
- static propTypes = {};
-};
-
-promise.then((result) => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? 'ok' : 'fail');

DELETE
packages/@romejs/js-formatter/test-fixtures/arrow/currying/output.js
-const fn = (b) => (c) => (d) => {
- return 3;
-};
-
-const foo = (a, b) => (c) => (d) => {
- return 3;
-};
-
-const bar = (a) => (b) => (c) => a + b + c;
-
-const mw = (store) => (next) => (action) => {
- return next(action);
-};
-
-const middleware = (options) => (req, res, next
-// ...
-) => {
-};

DELETE
packages/@romejs/js-formatter/test-fixtures/arrow/nested/output.js
-Seq(typeDef.interface.groups).forEach((group) => Seq(group.members).forEach((member, memberName) => markdownDoc(member.doc, {
- typePath: typePath.concat(memberName.slice(1)),
- signatures: member.signatures,
-})));
-
-const promiseFromCallback = (fn) => new Promise((resolve, reject) => fn((err, result) => {
- if (err) return reject(err);
- return resolve(result);
-}));
-
-runtimeAgent.getProperties(objectId, false, // ownProperties
-false, // accessorPropertiesOnly
-false, // generatePreview
-(error, properties, internalProperties) => {
- return 1;
-});

DELETE
packages/@romejs/js-formatter/test-fixtures/arrow/params/output.js
-fooooooooooooooooooooooooooooooooooooooooooooooooooo((action) => (next) => dispatch(action));
-
-foo(({
- a,
-
- b,
-}) => {});
-
-foo(({
- a,
- b,
-}) => {});
-
-foo(({
- a,
- b,
-}) => {});
-
-foo(a, ({
- a,
-
- b,
-}) => {});
-
-foo(({
- a,
-
- b,
-}) => a);
-
-foo(({
- a,
- b,
-}) => a);
-
-foo(({
- a,
- b,
-}) => a);
-
-foo(({
- a: {
- a,
-
- b,
- },
-}) => {});
-
-foo(({
- a: {
- b: {
- c,
-
- d,
- },
- },
-}) => {});
-
-foo(({
- a: {
- b: {
- c: {
- d,
-
- e,
- },
- },
- },
-}) => {});
-
-foo(({
- a: {
- a,
-
- b,
- },
-}) => a);
-
-foo(({
- a: {
- b: {
- c,
-
- d,
- },
- },
-}) => a);
-
-foo(({
- a: {
- b: {
- c: {
- d,
-
- e,
- },
- },
- },
-}) => a);
-
-foo(([
- {
- a: {
- b: {
- c: {
- d,
-
- e,
- },
- },
- },
- },
-]) => {});
-
-foo(([
-
-...{
- a: {
- b: {
- c: {
- d,
-
- e,
- },
- },
- },
-}]) => {});
-
-foo((n = {
- a: {
- b: {
- c: {
- d,
-
- e,
- },
- },
- },
-}) => {});
-
-foo(({
- x: [
- {
- a,
-
- b,
- },
- ],
-}) => {});
-
-foo((a = [
- {
- a,
-
- b,
- },
-]) => a);
-
-foo(([
- [
- {
- a,
-
- b,
- },
- ],
-]) => {});
-
-foo(([
- [
- [
- [
- {
- a,
- b: {
- c,
- d: {
- e,
-
- f,
- },
- },
- },
- ],
- ],
- ],
-]) => {});
-
-foo((...{
- a,
-
- b,
-}) => {});
-
-foo((...[
- {
- a,
-
- b,
- },
-]) => {});
-
-foo(([
-
-...[
- {
- a,
-
- b,
- },
-]]) => {});
-
-foo((a = [
- {
- a,
-
- b,
- },
-]) => {});
-
-foo((a = (({
- a,
-
- b,
-}) => {})()) => {});
-
-foo((a = f({
- a,
-
- b,
-})) => {});
-
-foo((a = ({
- a,
-
- b,
-}) => {}) => {});
-
-foo((a = 1 + f({
- a,
-
- b,
-})) => {});

update formatter tests