Commit Graph

10 Commits (master)

Author SHA1 Message Date
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
Ika 4af3dd4b07
test: improve snapshots (#5521)
- before
  ```
  ${input}${"~".repeat(printWidth)}
  ${output}
  ```
- after
  ```
  ===options===
  ${options}
  ${" ".repeat(printWidth)}| printWidth
  ====input====
  ${input}
  ===output====
  ${output}
  =============
  ```
2018-11-25 16:21:14 +08:00
Simen Bekkhus 51b7c02e12 Upgrade jest to 22 (#4782)
* chore: upgrade Jest

* chore: update snapshots

* chore: lock down babel dependency using invalid syntax

* 2 args to test.skip

* use jest 22 for now

* Revert "2 args to test.skip"

This reverts commit 691fdc3f99e320f2303958f2b503f7b4c93fa455.

* remove snapshot name from matcher

* fix standalone tests skips
2018-07-03 03:06:29 -03:00
Lucas Azzola b0cb63a7bb
Use destructuring for imports (#4554)
* Use destructuring for imports

* Clean up integration tests

* Use moduleNameMapper for require_prettier
2018-05-27 21:36:12 +10:00
Lucas Duailibe 5c6e0802af
Don't default parser to babylon (#4528)
* Don't default parser to babylon

* Different default values according to version

* Fix error logging

* Add tests specifically for parser inference

* Add another test case

* Add API test
2018-05-23 16:55:06 -03:00
David Sheldrick d77f5e9c3a Fix cursor offset tracking (#4397)
* handle cusor position relative to comments correctly

* use more robust method of cursor offset tracking

* add support for cursorOffset with rangeStart/End

* add tests for cursorOffset

* use old JS syntax for node4

* add another cursor offset test case

* remove trailing whitespace in cursor tests

* fix null findNodeAtOffset handling

* remove dead code

* add more test cases

* use indexOf for node4

* revert comments.js

* add more comment tests

* change tests infra

* Fix AST_COMPARE

* move CURSOR to top level of file

* mutate result

* use es6 property shorthand

* simplify diff offset calculation

* put remaining test cases in individual files
2018-05-01 09:42:59 -03:00
Simon Lydell 43cb08c45c Make production tests always run against dist/ (attempt 2) (#2942)
* Make production tests always run against dist/

* Try to mock process.stdin instead of get-stream

* fix: mock `get-stream` from `index.js`

* refactor: remove unnecessary variable

* Try `transform: {}` in jest.config.js

* Add comment explaining the unusual get-stream mocking
2017-10-02 17:58:55 +02:00
Joseph Frazier 48bbd9cb6b Don't insert a cursor placeholder for a value-less path (#2136)
* Test that no cursor placeholder is inserted for a value-less path

This was taken from https://github.com/prettier/prettier/issues/2131

* Don't insert a cursor placeholder for a value-less path

This fixes https://github.com/prettier/prettier/issues/2131
2017-06-14 09:05:06 -07:00
Joseph Frazier c863cbeac8 Translate cursor relative to nearest node, not SourceElement (#1989)
* Add test demonstrating SourceElement-relative cursor translation

See https://github.com/prettier/prettier/issues/1981#issuecomment-306326739

* Translate cursor relative to nearest node, not SourceElement

This partially address https://github.com/prettier/prettier/issues/1981

See https://github.com/prettier/prettier/issues/1981#issuecomment-306326739

* Add test demonstrating incorrect cursor translation

Since the `cursorOffset` option (introduced in #1637) works by tracking
the cursor position relative to an AST node (rather than a CST token),
it can produce incorrect results.

See https://github.com/prettier/prettier/issues/1981
2017-06-05 18:51:53 -07:00
Joseph Frazier 4bfeb9064d Add `cursorOffset` option for cursor translation (#1637)
* Add `formatWithCursor` API with `cursorOffset` option

This addresses https://github.com/prettier/prettier/issues/93 by
adding a new option, `cursorOffset`, that tells prettier to determine
the location of the cursor after the code has been formatted. This is
accessible through the API via a new function, `formatWithCursor`, which
returns a `{formatted: string, cursorOffset: ?number}`.

Here's a usage example:

```js
require("prettier").formatWithCursor(" 1", { cursorOffset: 2 });
// -> { formatted: '1;\n', cursorOffset: 1 }
```

* Add `--cursor-offset` CLI option

It will print out the offset instead of the formatted output. This
makes it easier to test. For example:

    echo ' 1' | prettier --stdin --cursor-offset 2
    # prints 1

* Add basic test of cursor translation

* Document `cursorOffset` option and `formatWithCursor()`

* Print translated cursor offset to stderr when --cursor-offset is given

This lets us continue to print the formatted code, while also
communicating the updated cursor position.

See https://github.com/prettier/prettier/pull/1637#discussion_r119735496

* doc-print cursor placeholder in comments.printComments()

See https://github.com/prettier/prettier/pull/1637#discussion_r119735149

* Compare array index to -1 instead of >= 0 to determine element presence

See https://github.com/prettier/prettier/pull/1637#discussion_r119736623

* Return {formatted, cursor} from printDocToString() instead of mutating options

See https://github.com/prettier/prettier/pull/1637#discussion_r119737354
2017-06-01 15:52:29 -07:00