-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: configurate browser tests (#123)
Co-authored-by: Siarhei Bautrukevich <[email protected]>
- Loading branch information
1 parent
2bc3f01
commit ad40735
Showing
6 changed files
with
127 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
process.env.CHROME_BIN = require('puppeteer').executablePath() | ||
|
||
const files = [ | ||
'../src/request/**.ts', | ||
'../src/tools/CancelController.ts', | ||
'../src/tools/errors.ts', | ||
'../src/tools/getUrl.ts', | ||
'./**/*.test.ts', | ||
] | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
browserNoActivityTimeout: 60000, | ||
browsers: ['ChromeHeadless'], | ||
reporters: ['progress', 'karma-typescript'], | ||
frameworks: ['jasmine', 'karma-typescript'], | ||
captureConsole: true, | ||
|
||
files, | ||
|
||
plugins: ['karma-typescript', 'karma-chrome-launcher', 'karma-jasmine'], | ||
|
||
preprocessors: files.reduce((conf, next) => { | ||
conf[next] = ['karma-typescript'] | ||
|
||
return conf | ||
}, {}), | ||
|
||
karmaTypescriptConfig: { | ||
bundlerOptions: { | ||
addNodeGlobals: true, | ||
constants: { 'process.env': { NODE_ENV: process.env.NODE_ENV } } | ||
}, | ||
compilerOptions: { | ||
target: 'es5', | ||
lib: ['es2015', 'dom'], | ||
strict: true, | ||
resolveJsonModule: true, | ||
noImplicitAny: false, | ||
strictNullChecks: true | ||
}, | ||
include: files, | ||
exclude: ['../node_modules', '../test'] | ||
} | ||
}) | ||
} |
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,72 @@ | ||
import CancelController from '../src/tools/CancelController' | ||
import { UploadClientError } from '../src/tools/errors' | ||
import request from '../src/request/request.browser' | ||
import getUrl from '../src/tools/getUrl' | ||
|
||
describe('request', () => { | ||
it('should post', async () => { | ||
const response = await request({ | ||
method: 'POST', | ||
url: getUrl('https://upload.uploadcare.com', '/base/', { | ||
jsonerrors: 1 | ||
}), | ||
data: new Blob(Array(1000).fill(1)) | ||
}) | ||
|
||
expect(response.request.method).toBe('POST') | ||
expect(response.status).toBe(200) | ||
expect(response.request.url).toBe( | ||
'https://upload.uploadcare.com/base/?jsonerrors=1' | ||
) | ||
expect(JSON.parse(response.data).error.content).toBe( | ||
'UPLOADCARE_PUB_KEY is required.' | ||
) | ||
}) | ||
|
||
it('should get', async () => { | ||
const response = await request({ | ||
url: getUrl('https://upload.uploadcare.com', '/from_url/status/', { | ||
token: 'test' | ||
}) | ||
}) | ||
|
||
expect(response.request.url).toBe( | ||
'https://upload.uploadcare.com/from_url/status/?token=test' | ||
) | ||
expect(response.request.method).toBe('GET') | ||
expect(JSON.parse(response.data).status).toBe('unknown') | ||
}) | ||
|
||
it('should be cancellable', async () => { | ||
const cancel = new CancelController() | ||
|
||
setTimeout(() => { | ||
cancel.cancel() | ||
}) | ||
|
||
await expectAsync( | ||
request({ | ||
url: getUrl('https://upload.uploadcare.com', '/from_url/status/', { | ||
token: 'test' | ||
}), | ||
cancel | ||
}) | ||
).toBeRejectedWithError(UploadClientError, 'Request canceled') | ||
}) | ||
|
||
it('should handle progress', async () => { | ||
const onProgress = jasmine.createSpy('progress') | ||
const response = await request({ | ||
method: 'POST', | ||
url: getUrl('https://upload.uploadcare.com', '/base/', { | ||
jsonerrors: 1 | ||
}), | ||
data: new Blob(Array(1000).fill(1)), | ||
onProgress | ||
}) | ||
|
||
expect(response.request.method).toBe('POST') | ||
expect(response.status).toBe(200) | ||
expect(onProgress).toHaveBeenCalled() | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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