-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from wix/app_logs
App logs
- Loading branch information
Showing
18 changed files
with
370 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const log = require('npmlog'); | ||
const sh = require('../utils/sh') | ||
|
||
class ArtifactsCopier { | ||
constructor(deviceDriver) { | ||
this._deviceDriver = deviceDriver; | ||
this._currentLaunchNumber = 0; | ||
this._currentTestArtifactsDestination = undefined; | ||
} | ||
|
||
prepare(deviceId) { | ||
this._deviceId = deviceId; | ||
} | ||
|
||
setArtifactsDestination(artifactsDestination) { | ||
this._currentTestArtifactsDestination = artifactsDestination; | ||
this._currentLaunchNumber = 1; | ||
} | ||
|
||
async handleAppRelaunch() { | ||
await this._copyArtifacts(); | ||
this._currentLaunchNumber++; | ||
} | ||
|
||
async finalizeArtifacts() { | ||
await this._copyArtifacts(); | ||
} | ||
|
||
async _copyArtifacts() { | ||
const copy = async (sourcePath, destinationSuffix) => { | ||
const destinationPath = `${this._currentTestArtifactsDestination}/${this._currentLaunchNumber}.${destinationSuffix}`; | ||
const cpArgs = `"${sourcePath}" "${destinationPath}"`; | ||
try { | ||
await sh.cp(cpArgs); | ||
} catch (ex) { | ||
log.warn(`Couldn't copy (cp ${cpArgs})`); | ||
} | ||
} | ||
|
||
if(this._currentTestArtifactsDestination === undefined) { | ||
return; | ||
} | ||
|
||
const {stdout, stderr} = this._deviceDriver.getLogsPaths(this._deviceId); | ||
const pathsMapping = [ | ||
[stdout, 'out.log'], | ||
[stderr, 'err.log'] | ||
]; | ||
for (const [sourcePath, destinationSuffix] of pathsMapping) { | ||
await copy(sourcePath, destinationSuffix); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = ArtifactsCopier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs'); | ||
const _ = require('lodash'); | ||
const log = require('npmlog'); | ||
|
||
class ArtifactsPathsProvider { | ||
constructor(destinationParent) { | ||
if(!destinationParent) { | ||
throw new Error('destinationParent should not be undefined'); | ||
} | ||
this._destinationRoot = `${destinationParent}/detox_artifacts.${new Date().toISOString()}`; | ||
try { | ||
fs.mkdirSync(this._destinationRoot); | ||
} catch (ex) { | ||
throw new Error(`Could not create artifacts root dir: ${this._destinationRoot}`); | ||
} | ||
} | ||
|
||
createPathForTest(number, ...nameComponents) { | ||
if(number !== parseInt(number) || number <= 0) { | ||
throw new Error('The number should be a positive integer'); | ||
} | ||
|
||
const lastPathComponent = [number].concat(nameComponents).join('.'); | ||
const pathForTest = `${this._destinationRoot}/${lastPathComponent}`; | ||
try { | ||
fs.mkdirSync(pathForTest); | ||
} catch (ex) { | ||
log.warn(`Could not create artifacts test dir: ${pathForTest}`); | ||
return undefined; | ||
} | ||
|
||
return pathForTest; | ||
} | ||
} | ||
|
||
module.exports = ArtifactsPathsProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const _ = require('lodash'); | ||
|
||
describe.only('ArtifactsPathsProvider', () => { | ||
let ArtifactsPathsProvider; | ||
let fs; | ||
let mockedDateString = '2017-07-13T06:31:48.544Z'; | ||
let log; | ||
|
||
beforeEach(() => { | ||
jest.mock('fs'); | ||
fs = require('fs'); | ||
jest.mock('npmlog'); | ||
log = require('npmlog'); | ||
|
||
ArtifactsPathsProvider = require('./ArtifactsPathsProvider'); | ||
require('mockdate').set(new Date(mockedDateString)); | ||
}); | ||
|
||
it('constructor - should throw on undefined destinationRoot', () => { | ||
expect(() => { | ||
new ArtifactsPathsProvider(); | ||
}).toThrowError(/undefined/); | ||
}); | ||
|
||
it('constructor - should throw if can\'t create run directory in the destination', () => { | ||
fs.mkdirSync = jest.fn(() => {throw 'some'}); | ||
expect(() => { | ||
new ArtifactsPathsProvider('/tmp'); | ||
}).toThrowError(/Could not create artifacts root dir/); | ||
}); | ||
|
||
it('createPathForTest() - should throw on invalid number', () => { | ||
function testForNumber(number) { | ||
expect(() => { | ||
(new ArtifactsPathsProvider('/tmp')).createPathForTest(number); | ||
}).toThrowError(/should be a positive integer/); | ||
} | ||
testForNumber(undefined); | ||
testForNumber('1'); | ||
testForNumber(-2); | ||
testForNumber(0); | ||
testForNumber('1.2'); | ||
}); | ||
|
||
it('createPathForTest() - should return proper path for no components', () => { | ||
expect((new ArtifactsPathsProvider('/tmp')).createPathForTest(1)). | ||
toEqual(`/tmp/detox_artifacts.${mockedDateString}/1`); | ||
}); | ||
|
||
it('createPathForTest() - should return proper path for no 1 component', () => { | ||
expect((new ArtifactsPathsProvider('/tmp')).createPathForTest(1, 'a')). | ||
toEqual(`/tmp/detox_artifacts.${mockedDateString}/1.a`); | ||
}); | ||
|
||
it('createPathForTest() - should return proper path for no 2 components', () => { | ||
expect((new ArtifactsPathsProvider('/tmp')).createPathForTest(1, 'a', 'b')). | ||
toEqual(`/tmp/detox_artifacts.${mockedDateString}/1.a.b`); | ||
}); | ||
|
||
it('createPathsForTest() - should catch mkdirSync exception', () => { | ||
const artifactsPathsProvider = new ArtifactsPathsProvider('/tmp'); | ||
fs.mkdirSync = jest.fn(() => {throw 'some'}); | ||
artifactsPathsProvider.createPathForTest(1); | ||
expect(log.warn).toHaveBeenCalledWith('Could not create artifacts test dir: /tmp/detox_artifacts.2017-07-13T06:31:48.544Z/1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.