Skip to content

Commit dac3270

Browse files
author
Ahmad Nassri
committed
fix: correct files entries array
1 parent 0f42174 commit dac3270

File tree

8 files changed

+23
-10
lines changed

8 files changed

+23
-10
lines changed

src/lib/files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core from '@actions/core'
1010

1111
export default async function (workspace, options) {
1212
// convert list of files to entries array
13-
const filesEntries = options.files.map(item => typeof item === 'string' ? [[item], item] : Object.entries(item).pop())
13+
const filesEntries = options.files.map(item => typeof item === 'string' ? [item, item] : Object.entries(item).pop())
1414

1515
// convert entries array to an object
1616
const filesObject = Object.fromEntries(filesEntries)

src/test/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('config does not exist', assert => {
4242
sinon.stub(core, 'setFailed')
4343
sinon.stub(process, 'exit')
4444

45-
config({ workspace: __dirname, path: 'fixtures/invalid.yml' })
45+
config({ workspace: __dirname, path: 'fixtures/configs/invalid.yml' })
4646

4747
// debug
4848
assert.ok(core.setFailed.calledWith('failed to parse config'))
@@ -56,7 +56,7 @@ test('valid config', assert => {
5656
sinon.stub(core, 'setFailed')
5757
sinon.stub(process, 'exit')
5858

59-
const options = config({ workspace: __dirname, path: 'fixtures/valid.yml' })
59+
const options = config({ workspace: __dirname, path: 'fixtures/configs/valid.yml' })
6060

6161
// debug
6262
assert.ok(core.debug.calledWith(`config loaded: ${inspect(options)}`))

src/test/files.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,43 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
1212
sinon.stub(core, 'info')
1313
sinon.stub(core, 'debug')
1414

15-
const workspace = join(__dirname, 'fixtures')
15+
const workspace = join(__dirname, 'fixtures/files')
1616

17-
test('lists files', async assert => {
17+
test('lists all files', async assert => {
1818
assert.plan(3)
1919

2020
const options = { files: [] }
2121

2222
const contents = await files(workspace, options)
2323

24+
assert.same(core.info.lastCall.args, ['found 3 files available to sync'])
25+
assert.same(core.debug.lastCall.args, [inspect(['file.1', 'file.2', 'file.3'])])
26+
27+
assert.equal(contents.size, 3)
28+
})
29+
30+
test('lists specific files', async assert => {
31+
assert.plan(3)
32+
33+
const options = { files: ['!file.3'] }
34+
35+
const contents = await files(workspace, options)
36+
2437
assert.same(core.info.lastCall.args, ['found 2 files available to sync'])
25-
assert.same(core.debug.lastCall.args, [inspect(['invalid.yml', 'valid.yml'])])
38+
assert.same(core.debug.lastCall.args, [inspect(['file.1', 'file.2'])])
2639

2740
assert.equal(contents.size, 2)
2841
})
2942

3043
test('lists remapped files', async assert => {
3144
assert.plan(3)
3245

33-
const options = { files: [{ 'valid.yml': '/new/path/new.name' }] }
46+
const options = { files: [{ 'file.1': '/new/path/new.name' }] }
3447

3548
const contents = await files(workspace, options)
3649

37-
assert.same(core.info.lastCall.args, ['found 2 files available to sync'])
38-
assert.same(core.debug.lastCall.args, [inspect(['/new/path/new.name', 'invalid.yml'])])
50+
assert.same(core.info.lastCall.args, ['found 3 files available to sync'])
51+
assert.same(core.debug.lastCall.args, [inspect(['/new/path/new.name', 'file.2', 'file.3'])])
3952

40-
assert.equal(contents.size, 2)
53+
assert.equal(contents.size, 3)
4154
})
File renamed without changes.
File renamed without changes.

src/test/fixtures/files/file.1

Whitespace-only changes.

src/test/fixtures/files/file.2

Whitespace-only changes.

src/test/fixtures/files/file.3

Whitespace-only changes.

0 commit comments

Comments
 (0)