Skip to content

Commit

Permalink
Fix uploadFile command (#6178)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Nov 30, 2020
1 parent e7195f9 commit 0d6944d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/wdio-logger/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('wdio-logger node', () => {

writableBuffer = scenario.writableBuffer

expect(await nodeLogger.waitForBuffer()).toBe(true)
expect(await nodeLogger.waitForBuffer()).toBe(undefined)
})
})

Expand Down Expand Up @@ -298,7 +298,7 @@ describe('wdio-logger node', () => {
})
describe('waitForBuffer with no logFile', () => {
it('should be ok if logFile is undefined', async () => {
expect(await nodeLogger.waitForBuffer()).toBe(true)
expect(await nodeLogger.waitForBuffer()).toBe(undefined)
})
})
})
13 changes: 8 additions & 5 deletions packages/webdriverio/src/commands/browser/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
const path = require('path');
it('should upload a file', function () {
const filePath = path.join(__dirname, '/local/path/to/your/file');
browser.url('https://the-internet.herokuapp.com/upload')
const remoteFilePath = browser.uploadFile(filePath);
$('.upload-data-file-input').setValue(remoteFilePath);
const filePath = '/path/to/some/file.png'
const remoteFilePath = browser.uploadFile(filePath)
$('#file-upload').setValue(remoteFilePath)
$('#file-submit').click()
});
* </example>
*
Expand All @@ -29,7 +32,7 @@ import archiver from 'archiver'
export default async function uploadFile (
this: WebdriverIO.BrowserObject,
localPath: string
): Promise<void> {
): Promise<string> {
/**
* parameter check
*/
Expand All @@ -53,7 +56,7 @@ export default async function uploadFile (
.on('data', (data: Uint8Array) => zipData.push(data))
.on('end', () => this.file(
Buffer.concat(zipData).toString('base64')
).then(() => resolve(), reject))
).then((localPath) => resolve(localPath), reject))
.append(source, { name: path.basename(localPath) })
.finalize()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('uploadFile', () => {
browserName: 'chrome'
}
})
browser.file = jest.fn().mockReturnValue(Promise.resolve())
browser.file = jest.fn().mockReturnValue(Promise.resolve('/some/local/path'))

const archiverMock = archiver()
const command = browser.uploadFile(path.resolve(__dirname, '..', '__fixtures__', 'toUpload.jpg'))
Expand All @@ -82,8 +82,9 @@ describe('uploadFile', () => {
archiverMock.on.mock.calls[1][1](Buffer.alloc(33))
archiverMock.on.mock.calls[2][1]()

await command
const localPath = await command
expect(browser.file).toBeCalledWith('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==')
expect(localPath).toBe('/some/local/path')
})

afterEach(() => {
Expand Down

0 comments on commit 0d6944d

Please sign in to comment.