Skip to content

Commit

Permalink
feat(file-system): add ability to remove files or directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Jul 19, 2017
1 parent 0b176bb commit eb82ed7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ fileSystem.install(defineSupportCode)
```yaml
Given:
- /^(?:I )?create directory (.+)$/
- /^(?:I )?remove (?:file|directory) (.+)$/

When:
# No definitions
Expand Down
9 changes: 8 additions & 1 deletion examples/features/file_system/file_system.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ Feature: File system extension
Scenario: Creating nested directory
Given I set cwd to examples/features/file_system/files
And I create directory deeply/nested/directory
Then directory deeply/nested/directory should exist
Then directory deeply/nested/directory should exist

Scenario: Creating and removing directory
Given I set cwd to examples/features/file_system/files
And I create directory deeply/nested/directory
Then directory deeply/nested/directory should exist
Given I remove directory deeply/nested/directory
Then directory deeply/nested/directory should not exist
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"git add"
],
"*.feature": [
"examples"
"cucumberjs --require examples/support examples/features --tags @offline"
],
"*.js": [
"lint-fix",
Expand Down
7 changes: 7 additions & 0 deletions src/extensions/file_system/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module.exports = ({ Given, Then }) => {
return this.fileSystem.createDirectory(this.cli.getCwd(), directory)
})

/**
* Remove a file or directory.
*/
Given(/^(?:I )?remove (?:file|directory) (.+)$/, function(fileOrDirectory) {
return this.fileSystem.remove(this.cli.getCwd(), fileOrDirectory)
})

/**
* Checking file/directory presence.
*/
Expand Down
17 changes: 10 additions & 7 deletions src/extensions/file_system/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ exports.getFileInfo = (cwd, file) =>
* @param {string} directory - Directory name
* @return {Promise.<boolean>}
*/
exports.createDirectory = (cwd, directory) =>
new Promise((resolve, reject) => {
fs.mkdirs(path.join(cwd, directory), err => {
if (err) return reject(err)
resolve(true)
})
})
exports.createDirectory = (cwd, directory) => fs.mkdirs(path.join(cwd, directory))

/**
* Removes a file or directory.
*
* @param {string} cwd - Current Working Directory
* @param {string} fileOrDirectory - File or directory name
* @return {Promise.<boolean>}
*/
exports.remove = (cwd, fileOrDirectory) => fs.remove(path.join(cwd, fileOrDirectory))

0 comments on commit eb82ed7

Please sign in to comment.