-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Replace node-module 'tempfile' seamlessly with 'tmp' #4777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const tmp = require('tmp'); | ||
|
||
tmp.setGracefulCleanup(); | ||
|
||
/** | ||
* Creates a temporary file path. If extension is provided, it will be appended to the path. | ||
* @param {string} [extension] - Optional file extension to append to the temporary file path | ||
* @returns {string} Path to a temporary file | ||
*/ | ||
module.exports = function(extension) { | ||
const _extension = (extension && extension.startsWith('.')) | ||
? extension | ||
: (extension && `.${extension}`); | ||
|
||
return tmp.tmpNameSync({ | ||
template: `detox-${process.pid}-XXXXXX${_extension || ''}`, | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
describe('tempfile', () => { | ||
let tmp; | ||
let tempfile; | ||
|
||
describe('in full integration with tmp module', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
tempfile = require('./tempfile'); | ||
}); | ||
|
||
it('should work with the real tmp module', () => { | ||
const tmpdir = require('node:os').tmpdir(); | ||
const path = require('node:path'); | ||
|
||
const expectedFile = path.join(tmpdir, `detox-${process.pid}-[a-zA-Z0-9]+.log`).replace(/\\/g, '\\\\'); | ||
const expectedResult = new RegExp(`^${expectedFile}$`); | ||
|
||
const result = tempfile('.log'); | ||
expect(result).toMatch(expectedResult); | ||
}); | ||
}); | ||
|
||
describe('with mocked tmp module', () => { | ||
beforeEach(() => { | ||
jest.mock('tmp'); | ||
tmp = require('tmp'); | ||
tempfile = require('./tempfile'); | ||
}); | ||
|
||
const expectTmpCalled = ({ withExtension = '' } = {}) => { | ||
const template = `detox-${process.pid}-XXXXXX${withExtension}`; | ||
expect(tmp.tmpNameSync).toHaveBeenCalledWith({ template }); | ||
}; | ||
|
||
it(`should enable tmp's graceful cleanup`, () => { | ||
expect(tmp.setGracefulCleanup).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return the value from tmp.tmpNameSync', () => { | ||
const mockPath = '/tmp/detox-123-abc123'; | ||
tmp.tmpNameSync.mockReturnValueOnce(mockPath); | ||
|
||
const result = tempfile(); | ||
expect(result).toEqual(mockPath); | ||
}); | ||
|
||
it('should create a temporary file path without extension', () => { | ||
tempfile(); | ||
expectTmpCalled(); | ||
}); | ||
|
||
it('should create a temporary file path with extension', () => { | ||
tempfile('txt'); | ||
expectTmpCalled({ withExtension: '.txt' }); | ||
}); | ||
|
||
it('should handle extension with leading dot', () => { | ||
tempfile('.txt'); | ||
expectTmpCalled({ withExtension: '.txt' }); | ||
}); | ||
|
||
it('should handle empty extension', () => { | ||
tempfile(''); | ||
expectTmpCalled(); | ||
}); | ||
|
||
it('should handle undefined extension', () => { | ||
tempfile(); | ||
expectTmpCalled(); | ||
}); | ||
}); | ||
}); |
Unchanged files with check annotations Beta
}); | ||
describe('- beforeAll hooks -', () => { | ||
it.skip('trigger false test_start glitch', () => {}); | ||
Check warning on line 14 in detox/test/e2e/23.flows.test.js
|
||
describe('inner suite', () => { | ||
beforeAll(async () => { |
await expect(faceid).toHaveText(RESULTS.DENIED); | ||
}); | ||
// todo: Skipped due to an error coming from react-native-permissions. Fix or implement a custom check. | ||
Check warning on line 170 in detox/test/e2e/13.permissions.test.js
|
||
it.skip('should grant permission', async () => { | ||
Check warning on line 171 in detox/test/e2e/13.permissions.test.js
|
||
const permissions = { faceid: 'YES' }; | ||
await device.launchApp({ permissions, delete: true }); |
await expect(element(by.id('UniqueId_AnimationsScreen_afterAnimationText'))).toBeVisible(); | ||
}); | ||
it.skip(`should not wait for infinite animations`, async () => { | ||
Check warning on line 44 in detox/test/e2e/12.animations.test.js
|
||
await _startTest(driver, { loops: -1 }); | ||
await expect(element(by.id('UniqueId_AnimationsScreen_afterAnimationText'))).toBeVisible(); | ||
}); |
await expect(element(by.text('From push'))).toExist(); | ||
}); | ||
xit('Init from calendar notification', async () => { | ||
Check warning on line 14 in detox/test/e2e/11.user-notifications.test.js
|
||
await device.launchApp({newInstance: true, userNotification: userNotificationCalendarTrigger}); | ||
await expect(element(by.text('From calendar'))).toExist(); | ||
}); | ||
await expect(element(by.text('From push'))).toExist(); | ||
}); | ||
xit('Background calendar notification', async () => { | ||
Check warning on line 26 in detox/test/e2e/11.user-notifications.test.js
|
||
await device.launchApp({newInstance: true}); | ||
await device.sendToHome(); | ||
await device.launchApp({newInstance: false, userNotification: userNotificationCalendarTrigger}); | ||
await expect(element(by.text('From push'))).toExist(); | ||
}); | ||
xit('Foreground calendar notifications', async () => { | ||
Check warning on line 39 in detox/test/e2e/11.user-notifications.test.js
|
||
await device.launchApp({newInstance: true}); | ||
await device.sendUserNotification(userNotificationCalendarTrigger); | ||
await expect(element(by.text('From calendar'))).toExist(); |
await expect(element(by.text('I contain some text'))).toHaveId('main-text'); | ||
}); | ||
it.skip(':ios: should assert an element has (accessibility) value', async () => { | ||
Check warning on line 49 in detox/test/e2e/04.assertions.test.js
|
||
await expect(driver.toggleElement).toHaveValue('0'); | ||
await driver.toggleElement.tap(); | ||
await expect(driver.toggleElement).toHaveValue('1'); |
}); | ||
}); | ||
it.skip(':android: should throw if tap handling is too slow', async () => { | ||
Check warning on line 99 in detox/test/e2e/03.actions.test.js
|
||
try { | ||
await driver.sluggishTapElement.tap(); | ||
} catch (e) { |
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}], | ||
// TODO: enable these rules gradually | ||
Check warning on line 21 in detox/test/.eslintrc.js
|
||
'comma-dangle': 0, | ||
'curly': 0, | ||
'eol-last': 0, |
const rnVersion = (function parseRNVersion() { | ||
let raw; | ||
try { | ||
const packageJson = require('react-native/package.json'); | ||
raw = packageJson.version; | ||
} catch { | ||
// Default version for RN |
const result = await this.withAction('scrollToView', traceDescription); | ||
// TODO Synchronization is not perfect here. We have to fix and remove this sleep ASAP. | ||
// See https://github.com/wix/Detox/issues/4741 | ||
await sleep(50); | ||
return result; |
const _ = require('lodash'); | ||
const { DetoxConfigErrorComposer } = require('../errors'); | ||
const argparse = require('../utils/argparse'); | ||
const asBoolean = (value) => { |
Uh oh!
There was an error while loading. Please reload this page.