Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed May 30, 2022
1 parent 0a9aed3 commit 87b5357
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 148 deletions.
4 changes: 4 additions & 0 deletions jest.config.units.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict'

// eslint-disable-next-line import/no-extraneous-dependencies
require('@babel/register')

module.exports = {
runner: 'jest-light-runner',
// Ignore 'tests' directory as it contains all the integration tests
modulePathIgnorePatterns: ['src/lambda/__tests__/fixtures/', 'tests/'],
}
6 changes: 3 additions & 3 deletions src/lambda/handler-runner/HandlerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export default class HandlerRunner {
return new WorkerThreadRunner(this.#funOptions, this.#env, allowCache)
}

const { default: InProcessRunner } = await import(
'./in-process-runner/index.js'
)
const {
default: { default: InProcessRunner },
} = await import('./in-process-runner/index.js')
return new InProcessRunner(
functionKey,
handlerPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export default class InProcessRunner {
if (!this.#allowCache) {
clearModule(this.#handlerPath, { cleanup: true })
}
const { [this.#handlerName]: handler } = await import(this.#handlerPath)
const { [this.#handlerName]: handler } = await import(
`${this.#handlerPath}.js`
)

if (typeof handler !== 'function') {
throw new Error(
Expand Down
144 changes: 1 addition & 143 deletions src/utils/__tests__/parseMultiValueQueryStringParameters.test.js
Original file line number Diff line number Diff line change
@@ -1,147 +1,5 @@
import parseMultiValueQueryStringParameters from '../parseMultiValueQueryStringParameters.js'

const tests = [
{
description: 'no parameter (empty string)',
expected: null,
expectedMulti: null,
param: '',
},

{
description: 'string parameter',
expected: { foo: 'bar' },
expectedMulti: { foo: ['bar'] },
param: 'foo=bar',
},

{
description: 'number parameter (no type casting)',
expected: { foo: '1' },
expectedMulti: { foo: ['1'] },
param: 'foo=1',
},

{
description: 'boolean parameter (no type casting)',
expected: { foo: 'true' },
expectedMulti: { foo: ['true'] },
param: 'foo=true',
},

{
description: 'multiple parameters',
expected: { bar: 'test2', foo: 'test1' },
expectedMulti: { bar: ['test2'], foo: ['test1'] },
param: 'foo=test1&bar=test2',
},

{
description: 'multiple parameters, same keys',
expected: { foo: 'foobar' },
expectedMulti: { foo: ['test', 'foobar'] },
param: 'foo=test&foo=foobar',
},

{
description: 'multiple parameters, same keys, different casing',
expected: { foo: 'test', FOO: 'FOOBAR' },
expectedMulti: { foo: ['test'], FOO: ['FOOBAR'] },
param: 'foo=test&FOO=FOOBAR',
},

{
description: 'multiple parameters, same keys, same values',
expected: { foo: 'test' },
expectedMulti: { foo: ['test', 'test'] },
param: 'foo=test&foo=test',
},

{
description: 'no value',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo',
},

{
description: 'no value with =',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo=',
},

{
description: 'no value with &',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo&',
},

{
description: 'no value with = and &',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo=&',
},

{
description: 'value is whitespace',
expected: { foo: ' ' },
expectedMulti: { foo: [' '] },
param: 'foo=%20',
},

{
description: 'key and value have whitespace',
expected: { ' foo ': ' test ' },
expectedMulti: { ' foo ': [' test '] },
param: '%20foo%20=%20test%20',
},

{
description: 'unicode',
expected: { Σ: '😋' },
expectedMulti: { Σ: ['😋'] },
param: 'Σ=😋',
},

{
description: 'encoded', // encodeURIComponent
expected: { '?=/&:': '?=/&:' },
expectedMulti: { '?=/&:': ['?=/&:'] },
param: '%3F%3D%2F%26%3A=%3F%3D%2F%26%3A',
},

{
description: 'end of line',
expected: { '\n': '\n' },
expectedMulti: { '\n': ['\n'] },
param: '%0A=%0A',
},

// silly test section:
{
description: 'silly I.',
expected: { test: '?' },
expectedMulti: { test: ['?'] },
param: 'test=?',
},

{
description: 'silly II.',
expected: { test: '/' },
expectedMulti: { test: ['/'] },
param: 'test=/',
},

{
description: 'silly III.',
expected: { test: '=' },
expectedMulti: { test: ['='] },
param: 'test==',
},
]
import tests from './tests/parseQueryStringParameters.js'

describe('parseMultiValueQueryStringParameters', () => {
tests.forEach(({ description, expectedMulti, param }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__tests__/parseQueryStringParameters.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// uses the same tests as parseMultiValueQueryStringParameters
import tests from './parseMultiValueQueryStringParameters.test.js'
import parseQueryStringParameters from '../parseQueryStringParameters.js'
import tests from './tests/parseQueryStringParameters.js'

describe('parseQueryStringParameters', () => {
tests.forEach(({ description, expected, param }) => {
Expand Down
142 changes: 142 additions & 0 deletions src/utils/__tests__/tests/parseQueryStringParameters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
export default [
{
description: 'no parameter (empty string)',
expected: null,
expectedMulti: null,
param: '',
},

{
description: 'string parameter',
expected: { foo: 'bar' },
expectedMulti: { foo: ['bar'] },
param: 'foo=bar',
},

{
description: 'number parameter (no type casting)',
expected: { foo: '1' },
expectedMulti: { foo: ['1'] },
param: 'foo=1',
},

{
description: 'boolean parameter (no type casting)',
expected: { foo: 'true' },
expectedMulti: { foo: ['true'] },
param: 'foo=true',
},

{
description: 'multiple parameters',
expected: { bar: 'test2', foo: 'test1' },
expectedMulti: { bar: ['test2'], foo: ['test1'] },
param: 'foo=test1&bar=test2',
},

{
description: 'multiple parameters, same keys',
expected: { foo: 'foobar' },
expectedMulti: { foo: ['test', 'foobar'] },
param: 'foo=test&foo=foobar',
},

{
description: 'multiple parameters, same keys, different casing',
expected: { foo: 'test', FOO: 'FOOBAR' },
expectedMulti: { foo: ['test'], FOO: ['FOOBAR'] },
param: 'foo=test&FOO=FOOBAR',
},

{
description: 'multiple parameters, same keys, same values',
expected: { foo: 'test' },
expectedMulti: { foo: ['test', 'test'] },
param: 'foo=test&foo=test',
},

{
description: 'no value',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo',
},

{
description: 'no value with =',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo=',
},

{
description: 'no value with &',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo&',
},

{
description: 'no value with = and &',
expected: { foo: '' },
expectedMulti: { foo: [''] },
param: 'foo=&',
},

{
description: 'value is whitespace',
expected: { foo: ' ' },
expectedMulti: { foo: [' '] },
param: 'foo=%20',
},

{
description: 'key and value have whitespace',
expected: { ' foo ': ' test ' },
expectedMulti: { ' foo ': [' test '] },
param: '%20foo%20=%20test%20',
},

{
description: 'unicode',
expected: { Σ: '😋' },
expectedMulti: { Σ: ['😋'] },
param: 'Σ=😋',
},

{
description: 'encoded', // encodeURIComponent
expected: { '?=/&:': '?=/&:' },
expectedMulti: { '?=/&:': ['?=/&:'] },
param: '%3F%3D%2F%26%3A=%3F%3D%2F%26%3A',
},

{
description: 'end of line',
expected: { '\n': '\n' },
expectedMulti: { '\n': ['\n'] },
param: '%0A=%0A',
},

// silly test section:
{
description: 'silly I.',
expected: { test: '?' },
expectedMulti: { test: ['?'] },
param: 'test=?',
},

{
description: 'silly II.',
expected: { test: '/' },
expectedMulti: { test: ['/'] },
param: 'test=/',
},

{
description: 'silly III.',
expected: { test: '=' },
expectedMulti: { test: ['='] },
param: 'test==',
},
]

0 comments on commit 87b5357

Please sign in to comment.