Skip to content

Commit

Permalink
feat(core): fs.assert trim when match content
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 26, 2021
1 parent 3022c14 commit e7e0262
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/core/lib/actions/fs/assert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/lib/actions/log/md.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/src/actions/fs/assert.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ console.info(`File exists: ${status}`)
{data} = await @fs.base.readFile config.target
for filter in config.filter or []
data = filter[Symbol.replace] data, ''
data = utils.buffer.trim data, config.encoding if config.trim
unless config.not
unless config.content.test data
throw errors.NIKITA_FS_ASSERT_CONTENT_UNMATCH config: config, expect: data
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/log/md.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Write log to the host filesystem in Markdown.
state.last_event_type = 'text'
content = []
content.push "\n#{log.message}"
content.push " (#{log.depth}.#{log.level}, written by #{log.module})" if log.module
content.push " (#{log.depth}.#{log.level}, written by #{log.module})" if log.module and log.module isnt '@nikitajs/core/src/actions/call'
content.push "\n"
content.join ''
Expand Down
28 changes: 25 additions & 3 deletions packages/core/test/actions/fs/assert.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ describe 'actions.fs.assert', ->

describe 'config `trim`', ->

they 'trim target', ({ssh}) ->
they 'on target against content string', ({ssh}) ->
nikita
ssh: ssh
metadata: tmpdir: true
Expand All @@ -543,8 +543,30 @@ describe 'actions.fs.assert', ->
target: "#{tmpdir}/a_file"
content: 'ok'
trim: true

they 'on target against content buffer', ({ssh}) ->
nikita
ssh: ssh
metadata: tmpdir: true
, ({metadata: {tmpdir}}) ->
@fs.base.writeFile "#{tmpdir}/a_file", content: '\nok\n'
@fs.assert
target: "#{tmpdir}/a_file"
content: Buffer.from 'ok'
trim: true

they 'on target against content regexp', ({ssh}) ->
nikita
ssh: ssh
metadata: tmpdir: true
, ({metadata: {tmpdir}}) ->
@fs.base.writeFile "#{tmpdir}/a_file", content: '\nok\n'
@fs.assert
target: "#{tmpdir}/a_file"
content: /^ok$/
trim: true

they 'trim content string', ({ssh}) ->
they 'with content string', ({ssh}) ->
nikita
ssh: ssh
metadata: tmpdir: true
Expand All @@ -555,7 +577,7 @@ describe 'actions.fs.assert', ->
content: '\nok\n'
trim: true

they 'trim content buffer', ({ssh}) ->
they 'with content buffer', ({ssh}) ->
nikita
ssh: ssh
metadata: tmpdir: true
Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/actions/log/md.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe 'actions.log.md', ->
/^Entering.*$/mg
]
target: "#{tmpdir}/localhost.log"
content: "ok"
content: 'ok'

they 'write message and module', ({ssh}) ->
nikita
Expand Down Expand Up @@ -70,6 +70,7 @@ describe 'actions.log.md', ->
trim: true
filter: [
/^Entering.*$/mg
/^\n$/mg
]
target: "#{tmpdir}/localhost.log"
content: """
Expand All @@ -95,6 +96,7 @@ describe 'actions.log.md', ->
trim: true
filter: [
/^Entering.*$/mg
/^\n$/mg
]
target: "#{tmpdir}/localhost.log"
content: """
Expand Down

0 comments on commit e7e0262

Please sign in to comment.