Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4461] Change typescript declaration for .writeFile() #4463

Merged
merged 5 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,13 +1776,21 @@ declare namespace Cypress {
})
```
*/
writeFile<C extends FileContents>(filePath: string, contents: C, options?: Partial<Loggable>): Chainable<C>
writeFile<C extends FileContents>(filePath: string, contents: C, encoding: Encodings): Chainable<C>
/**
* Write to a file with the specified encoding and contents.
*
* @see https://on.cypress.io/writefile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an example here?

```
cy.writeFile('path/to/ascii.txt', 'Hello World', {
flag: 'a+',
encoding: 'ascii'
}).then((text) => {
expect(text).to.equal('Hello World') // true
})
```
*/
writeFile<C extends FileContents>(filePath: string, contents: C, encoding: Encodings, options?: Partial<Loggable>): Chainable<C>
writeFile<C extends FileContents>(filePath: string, contents: C, options?: Partial<WriteFileOptions>): Chainable<C>

/**
* jQuery library bound to the AUT
Expand Down Expand Up @@ -2318,6 +2326,12 @@ declare namespace Cypress {
cancelable: boolean
}

/** Options to change the default behavior of .writeFile */
interface WriteFileOptions extends Loggable {
flag: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flag is only string even in native node's fs declarations

encoding: Encodings
}

// Kind of onerous, but has a nice auto-complete. Also fallbacks at the end for custom stuff
/**
* @see https://on.cypress.io/should
Expand Down
6 changes: 6 additions & 0 deletions cli/types/tests/chainer-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,9 @@ cy
})

cy.get('#result').should('have.text', 'John Doe')

cy.writeFile('../file.path', '', 'utf-8')
cy.writeFile('../file.path', '', {
flag: 'a+',
encoding: 'utf-8'
})