Skip to content

Commit

Permalink
fix(artifacts): context logic in base artifact plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Jan 3, 2020
1 parent c222bf5 commit c64d98f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 58 deletions.
4 changes: 2 additions & 2 deletions detox/src/artifacts/log/ios/SimulatorLogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SimulatorLogPlugin extends LogArtifactPlugin {

if (this.currentRecording) {
await this.currentRecording.start({
udid: this.context.deviceId,
bundleId: this.context.bundleId,
udid: event.deviceId,
bundleId: event.bundleId,
});
}
}
Expand Down
38 changes: 8 additions & 30 deletions detox/src/artifacts/templates/plugin/ArtifactPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ class ArtifactPlugin {
* @param {Object} event.launchArgs - Mutable key-value pairs of args before the launch
* @return {Promise<void>} - when done
*/
async onBeforeLaunchApp(event) {
Object.assign(this.context, {
bundleId: event.bundleId,
deviceId: event.deviceId,
launchArgs: event.launchArgs,
pid: NaN,
});
}
async onBeforeLaunchApp(event) {}

/**
* Hook that is called inside device.launchApp() and
Expand All @@ -72,7 +65,6 @@ class ArtifactPlugin {
async onLaunchApp(event) {
Object.assign(this.context, {
bundleId: event.bundleId,
deviceId: event.deviceId,
launchArgs: event.launchArgs,
pid: event.pid,
});
Expand All @@ -91,8 +83,6 @@ class ArtifactPlugin {
async onBootDevice(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
bundleId: '',
pid: NaN,
});
}

Expand All @@ -106,12 +96,7 @@ class ArtifactPlugin {
* @param {string} event.bundleId - Current bundleId
* @return {Promise<void>} - when done
*/
async onBeforeTerminateApp(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
bundleId: event.bundleId,
});
}
async onBeforeTerminateApp(event) {}

/**
* Hook that is supposed to be called after app has been terminated
Expand All @@ -125,8 +110,9 @@ class ArtifactPlugin {
*/
async onTerminateApp(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
bundleId: '',
launchArgs: null,
pid: NaN,
});
}

Expand All @@ -140,12 +126,7 @@ class ArtifactPlugin {
* @param {string} event.bundleId - Current bundleId
* @return {Promise<void>} - when done
*/
async onBeforeUninstallApp(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
bundleId: event.bundleId,
});
}
async onBeforeUninstallApp(event) {}

/**
* Hook that is supposed to be called before device.shutdown() happens
Expand All @@ -156,11 +137,7 @@ class ArtifactPlugin {
* @param {string} event.deviceId - Current deviceId
* @return {Promise<void>} - when done
*/
async onBeforeShutdownDevice(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
});
}
async onBeforeShutdownDevice(event) {}

/**
* Hook that is supposed to be called from device.shutdown()
Expand All @@ -173,8 +150,9 @@ class ArtifactPlugin {
*/
async onShutdownDevice(event) {
Object.assign(this.context, {
deviceId: event.deviceId,
deviceId: '',
bundleId: '',
launchArgs: null,
pid: NaN,
});
}
Expand Down
46 changes: 20 additions & 26 deletions detox/src/artifacts/templates/plugin/ArtifactPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ describe('ArtifactPlugin', () => {
describe('lifecycle hooks', () => {
beforeEach(() => {
plugin.context = {
deviceId: 'shouldNotBeInExpectSnapshots',
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty'
};
});

it('should update context on .onBeforeLaunchApp', async () => {
it('should not update context on .onBeforeLaunchApp', async () => {
await expect(plugin.onBeforeLaunchApp({
deviceId: 'testDeviceId',
bundleId: 'testBundleId',
Expand All @@ -88,17 +88,12 @@ describe('ArtifactPlugin', () => {
}));

expect(plugin.context).toEqual({
bundleId: 'testBundleId',
deviceId: 'testDeviceId',
launchArgs: {
detoxSessionId: 'test',
},
pid: NaN,
shouldNotBeDeletedFromContext: 'extraProperty',
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty'
});
});

it('should have .onLaunchApp', async () => {
it('should update context .onLaunchApp', async () => {
await expect(plugin.onLaunchApp({
deviceId: 'testDeviceId',
bundleId: 'testBundleId',
Expand All @@ -110,7 +105,7 @@ describe('ArtifactPlugin', () => {

expect(plugin.context).toEqual({
bundleId: 'testBundleId',
deviceId: 'testDeviceId',
deviceId: 'someOriginalDeviceId',
launchArgs: {
detoxSessionId: 'test',
},
Expand All @@ -119,29 +114,27 @@ describe('ArtifactPlugin', () => {
});
});

it('should update context on .onBeforeUninstallApp', async () => {
it('should not update context on .onBeforeUninstallApp', async () => {
await expect(plugin.onBeforeUninstallApp({
deviceId: 'testDeviceId',
bundleId: 'testBundleId',
}));

expect(plugin.context).toEqual({
bundleId: 'testBundleId',
deviceId: 'testDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty',
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty'
});
});

it('should update context on .onBeforeTerminateApp', async () => {
it('should not update context on .onBeforeTerminateApp', async () => {
await expect(plugin.onBeforeTerminateApp({
deviceId: 'testDeviceId',
bundleId: 'testBundleId',
}));

expect(plugin.context).toEqual({
bundleId: 'testBundleId',
deviceId: 'testDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty',
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty'
});
});

Expand All @@ -153,32 +146,32 @@ describe('ArtifactPlugin', () => {

expect(plugin.context).toEqual({
bundleId: '',
deviceId: 'testDeviceId',
launchArgs: null,
pid: NaN,
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty',
});
});

it('should have .onBootDevice', async () => {
it('should update context on .onBootDevice', async () => {
await expect(plugin.onBootDevice({
deviceId: 'testDeviceId',
coldBoot: true
}));

expect(plugin.context).toEqual({
bundleId: '',
deviceId: 'testDeviceId',
pid: NaN,
shouldNotBeDeletedFromContext: 'extraProperty',
});
});

it('should have .onBeforeShutdownDevice', async () => {
it('should not update context on .onBeforeShutdownDevice', async () => {
await expect(plugin.onBeforeShutdownDevice({
deviceId: 'testDeviceId'
}));

expect(plugin.context).toEqual({
deviceId: 'testDeviceId',
deviceId: 'someOriginalDeviceId',
shouldNotBeDeletedFromContext: 'extraProperty',
});
});
Expand All @@ -189,8 +182,9 @@ describe('ArtifactPlugin', () => {
}));

expect(plugin.context).toEqual({
deviceId: '',
bundleId: '',
deviceId: 'testDeviceId',
launchArgs: null,
pid: NaN,
shouldNotBeDeletedFromContext: 'extraProperty',
});
Expand Down

0 comments on commit c64d98f

Please sign in to comment.