Skip to content

Commit

Permalink
meta: prepare test files for lint rule hardening (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed May 23, 2022
1 parent bf1489e commit 5a8a8d3
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 31 deletions.
3 changes: 3 additions & 0 deletions packages/@uppy/audio/package.json
Expand Up @@ -29,6 +29,9 @@
"@uppy/utils": "workspace:^",
"preact": "^10.5.13"
},
"devDependencies": {
"@jest/globals": "^27.4.2"
},
"peerDependencies": {
"@uppy/core": "workspace:^"
},
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/audio/src/formatSeconds.test.js
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import formatSeconds from './formatSeconds.js'

describe('formatSeconds', () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/@uppy/audio/src/supportsMediaRecorder.test.js
@@ -1,22 +1,23 @@
/* eslint-disable max-classes-per-file */
import { describe, expect, it } from '@jest/globals'
import supportsMediaRecorder from './supportsMediaRecorder.js'

describe('supportsMediaRecorder', () => {
it('should return true if MediaRecorder is supported', () => {
global.MediaRecorder = class MediaRecorder {
globalThis.MediaRecorder = class MediaRecorder {
start () {} // eslint-disable-line
}
expect(supportsMediaRecorder()).toEqual(true)
})

it('should return false if MediaRecorder is not supported', () => {
global.MediaRecorder = undefined
globalThis.MediaRecorder = undefined
expect(supportsMediaRecorder()).toEqual(false)

global.MediaRecorder = class MediaRecorder {}
globalThis.MediaRecorder = class MediaRecorder {}
expect(supportsMediaRecorder()).toEqual(false)

global.MediaRecorder = class MediaRecorder {
globalThis.MediaRecorder = class MediaRecorder {
foo () {} // eslint-disable-line
}
expect(supportsMediaRecorder()).toEqual(false)
Expand Down
8 changes: 4 additions & 4 deletions packages/@uppy/aws-s3-multipart/src/index.test.js
@@ -1,4 +1,4 @@
import { describe, expect, it, jest } from '@jest/globals'
import { beforeEach, describe, expect, it, jest } from '@jest/globals'

import 'whatwg-fetch'
import nock from 'nock'
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('AwsS3Multipart', () => {
source: 'jest',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([Buffer.alloc(fileSize)], {
data: new File([new Uint8Array(fileSize)], {
type: 'application/octet-stream',
}),
})
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('AwsS3Multipart', () => {
source: 'jest',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([Buffer.alloc(fileSize)], {
data: new File([new Uint8Array(fileSize)], {
type: 'application/octet-stream',
}),
})
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('AwsS3Multipart', () => {
source: 'jest',
name: 'multitest.dat',
type: 'application/octet-stream',
data: new File([Buffer.alloc(fileSize)], {
data: new File([new Uint8Array(fileSize)], {
type: 'application/octet-stream',
}),
})
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3/package.json
Expand Up @@ -29,6 +29,7 @@
"nanoid": "^3.1.25"
},
"devDependencies": {
"@jest/globals": "^27.4.2",
"whatwg-fetch": "3.6.2"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3/src/index.test.js
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import 'whatwg-fetch'
import Core from '@uppy/core'
import AwsS3 from './index.js'
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3/src/isXml.test.js
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import isXml from './isXml.js'

describe('AwsS3', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/companion-client/src/Socket.test.js
@@ -1,4 +1,4 @@
import { jest, describe, it, expect } from '@jest/globals'
import { afterEach, beforeEach, jest, describe, it, expect } from '@jest/globals'
import UppySocket from './Socket.js'

describe('Socket', () => {
Expand All @@ -11,7 +11,7 @@ describe('Socket', () => {
webSocketCloseSpy = jest.fn()
webSocketSendSpy = jest.fn()

global.WebSocket = class WebSocket {
globalThis.WebSocket = class WebSocket {
constructor (target) {
webSocketConstructorSpy(target)
}
Expand All @@ -36,7 +36,7 @@ describe('Socket', () => {
}
})
afterEach(() => {
global.WebSocket = undefined
globalThis.WebSocket = undefined
})

it('should expose a class', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/src/index.test.js
@@ -1,4 +1,4 @@
import { describe, it, expect } from '@jest/globals'
import { afterAll, beforeAll, describe, it, expect } from '@jest/globals'

import Core from '@uppy/core'
import StatusBarPlugin from '@uppy/status-bar'
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/store-default/package.json
Expand Up @@ -15,6 +15,9 @@
"bugs": {
"url": "https://github.com/transloadit/uppy/issues"
},
"devDependencies": {
"@jest/globals": "^27.4.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/transloadit/uppy.git"
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/store-default/src/index.test.js
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import DefaultStore from './index.js'

describe('DefaultStore', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/thumbnail-generator/src/index.test.js
@@ -1,4 +1,4 @@
import { describe, it, expect, jest } from '@jest/globals'
import { afterEach, beforeEach, describe, it, expect, jest, xit } from '@jest/globals'
import { UIPlugin } from '@uppy/core'
import emitter from 'namespace-emitter'
import ThumbnailGeneratorPlugin from './index.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/transloadit/src/Assembly.js
Expand Up @@ -12,7 +12,7 @@ import parseUrl from './parseUrl.js'
// TODO: remove this hack in the next release.
let socketIo
function requireSocketIo () {
// eslint-disable-next-line no-return-assign, no-restricted-globals, global-require
// eslint-disable-next-line no-return-assign, no-restricted-globals, global-require, no-undef
return socketIo ??= require('socket.io-client')
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/transloadit/src/AssemblyOptions.test.js
Expand Up @@ -20,7 +20,7 @@ describe('Transloadit/AssemblyOptions', () => {
})

it('Uses different assemblies for different params', async () => {
const data = Buffer.alloc(10)
const data = new Uint8Array(10)
data.size = data.byteLength

const options = new AssemblyOptions([
Expand Down Expand Up @@ -48,8 +48,8 @@ describe('Transloadit/AssemblyOptions', () => {
})

it('Should merge files with same parameters into one Assembly', async () => {
const data = Buffer.alloc(10)
const data2 = Buffer.alloc(20)
const data = new Uint8Array(10)
const data2 = new Uint8Array(20)

const options = new AssemblyOptions([
{ name: 'a.png', data, size: data.byteLength },
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/webcam/package.json
Expand Up @@ -30,6 +30,9 @@
"@uppy/utils": "workspace:^",
"preact": "^10.5.13"
},
"devDependencies": {
"@jest/globals": "^27.4.2"
},
"peerDependencies": {
"@uppy/core": "workspace:^"
}
Expand Down
15 changes: 8 additions & 7 deletions packages/@uppy/webcam/src/Webcam.test.js
@@ -1,10 +1,11 @@
import { describe, expect, it } from '@jest/globals'
import Uppy from '@uppy/core'
import Webcam from '../lib/index.js'

describe('Webcam', () => {
describe('_getMediaRecorderOptions', () => {
it('should not have a mimeType set if no preferences given', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}

Expand All @@ -15,7 +16,7 @@ describe('Webcam', () => {
})

it('should use preferredVideoMimeType', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}

Expand All @@ -26,7 +27,7 @@ describe('Webcam', () => {
})

it('should not use preferredVideoMimeType if it is not supported', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}

Expand All @@ -37,7 +38,7 @@ describe('Webcam', () => {
})

it('should pick type based on `allowedFileTypes`', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}

Expand All @@ -50,7 +51,7 @@ describe('Webcam', () => {
})

it('should use first supported type from allowedFileTypes', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}

Expand All @@ -63,7 +64,7 @@ describe('Webcam', () => {
})

it('should prefer preferredVideoMimeType over allowedFileTypes', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}

Expand All @@ -77,7 +78,7 @@ describe('Webcam', () => {
})

it('should not use allowedFileTypes if they are unsupported', () => {
global.MediaRecorder = {
globalThis.MediaRecorder = {
isTypeSupported: () => false,
}

Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/webcam/src/formatSeconds.test.js
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import formatSeconds from './formatSeconds.js'

describe('formatSeconds', () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/@uppy/webcam/src/supportsMediaRecorder.test.js
@@ -1,22 +1,23 @@
/* eslint-disable max-classes-per-file, class-methods-use-this */
import { describe, expect, it } from '@jest/globals'
import supportsMediaRecorder from './supportsMediaRecorder.js'

describe('supportsMediaRecorder', () => {
it('should return true if MediaRecorder is supported', () => {
global.MediaRecorder = class MediaRecorder {
globalThis.MediaRecorder = class MediaRecorder {
start () {}
}
expect(supportsMediaRecorder()).toEqual(true)
})

it('should return false if MediaRecorder is not supported', () => {
global.MediaRecorder = undefined
globalThis.MediaRecorder = undefined
expect(supportsMediaRecorder()).toEqual(false)

global.MediaRecorder = class MediaRecorder {}
globalThis.MediaRecorder = class MediaRecorder {}
expect(supportsMediaRecorder()).toEqual(false)

global.MediaRecorder = class MediaRecorder {
globalThis.MediaRecorder = class MediaRecorder {
foo () {}
}
expect(supportsMediaRecorder()).toEqual(false)
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/xhr-upload/src/index.test.js
Expand Up @@ -27,7 +27,7 @@ describe('XHRUpload', () => {
})
core.addFile({
name: 'test.jpg',
data: new Blob([Buffer.alloc(8192)]),
data: new Blob([new Uint8Array(8192)]),
})

return core.upload().then(() => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('XHRUpload', () => {
})
core.addFile({
name: 'test.jpg',
data: new Blob([Buffer.alloc(8192)]),
data: new Blob([new Uint8Array(8192)]),
})

return core.upload().then(result => {
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('XHRUpload', () => {
})
core.addFile({
name: 'test.jpg',
data: new Blob([Buffer.alloc(8192)]),
data: new Blob([new Uint8Array(8192)]),
})

await core.upload()
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -9662,6 +9662,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy/audio@workspace:packages/@uppy/audio"
dependencies:
"@jest/globals": ^27.4.2
"@uppy/utils": "workspace:^"
preact: ^10.5.13
peerDependencies:
Expand All @@ -9687,6 +9688,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy/aws-s3@workspace:packages/@uppy/aws-s3"
dependencies:
"@jest/globals": ^27.4.2
"@uppy/companion-client": "workspace:^"
"@uppy/utils": "workspace:^"
"@uppy/xhr-upload": "workspace:^"
Expand Down Expand Up @@ -10117,6 +10119,8 @@ __metadata:
"@uppy/store-default@workspace:^, @uppy/store-default@workspace:packages/@uppy/store-default":
version: 0.0.0-use.local
resolution: "@uppy/store-default@workspace:packages/@uppy/store-default"
dependencies:
"@jest/globals": ^27.4.2
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -10249,6 +10253,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy/webcam@workspace:packages/@uppy/webcam"
dependencies:
"@jest/globals": ^27.4.2
"@uppy/utils": "workspace:^"
preact: ^10.5.13
peerDependencies:
Expand Down

0 comments on commit 5a8a8d3

Please sign in to comment.