Skip to content

Commit

Permalink
tests linting
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Dec 20, 2023
1 parent e75bfc8 commit 4031b81
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 145 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"version": "1.0.0",
"description": "light and fast module to convert iso country and languages codes into country names, there is no unnecessary stuff only the bare essentials",
"scripts": {
"prepare": "husky install",
"clean": "node bin/clean.mjs",
"module-cjs": "swc src -d lib/cjs -C module.type=commonjs --config-file .swcrc-cjs",
"module-esm": "swc src -d lib/esm -C module.type=es6 --config-file .swcrc-esm",
"module-umd": "npx spack",
"module-browser": "npx esbuild src/isoToLanguage.ts --outdir=lib/browser --allow-overwrite --bundle --minify --sourcemap",
"build": "pnpm run clean && concurrently pnpm:module-* && pnpm run types",
"types": "tsc -p tsconfig.json --module Node16 --emitDeclarationOnly --declaration --declarationDir ./lib/@types --skipLibCheck",
"lint": "eslint ./src --fix",
"clean": "node bin/clean.mjs",
"test": "jest",
"prepare": "husky install"
"test": "jest"
},
"license": "ISC",
"main": "./lib/esm/index.js",
Expand Down Expand Up @@ -56,23 +56,27 @@
"@swc/cli": "^0.1.63",
"@swc/core": "1.2.239",
"@swc/jest": "^0.2.29",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
"@types/webpack": "^5.28.5",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"concurrently": "^8.2.2",
"eslint": "^8.55.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-n": "^16.3.1",
"eslint-plugin-promise": "^6.1.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"concurrently": "^8.2.2",
"prettier": "^2.8.8",
"typescript": "^5.3.3"
},
"lint-staged": {
"tests/**/*.{ts}": [
"prettier --write"
],
"src/**/*.{ts}": [
"eslint --fix",
"prettier --write",
Expand Down
4 changes: 3 additions & 1 deletion tests/getAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ describe('getAll', () => {
expect(result).toEqual(expect.arrayContaining(expected as unknown[]))
} else {
// For other types, test objects
expect(result).toMatchObject(expected as Record<string, unknown> | Record<string, unknown>[])
expect(result).toMatchObject(
expected as Record<string, unknown> | Record<string, unknown>[]
)
}
})
})
Expand Down
3 changes: 2 additions & 1 deletion tests/getAllLanguageCodesByISO.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { describe, expect } from '@jest/globals'
import { getAllLanguagesByISO } from '../src/'
import { isoCountries } from '../src/countries'
import { ISOCode } from '../src/types'

describe('getAllLanguagesByISO', () => {
it('should return all languages associated with the given ISO codes', () => {
const isoCodes = ['AD', 'AE', 'AF']
const result = getAllLanguagesByISO(isoCodes)
const expectedLanguages = Array.from(
new Set(isoCodes.flatMap((isoCode) => isoCountries[isoCode].languages))
new Set(isoCodes.flatMap((isoCode) => isoCountries[isoCode as ISOCode].languages))
)

expect(result).toEqual(expectedLanguages)
Expand Down
8 changes: 6 additions & 2 deletions tests/getAllLanguagesByISO.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe('getAllLanguageCodesByISO', () => {
const expectedLanguageCodes = Array.from(
new Set(
isoCodes.flatMap((isoCode) => {
return isoCountries[isoCode].languages.map((language) => `${language}-${isoCode}`)
return isoCountries[isoCode].languages.map(
(language) => `${language}-${isoCode}`
)
})
)
)
Expand All @@ -23,7 +25,9 @@ describe('getAllLanguageCodesByISO', () => {
const expectedLanguageCodes = Array.from(
new Set(
isoCodes.flatMap((isoCode) => {
return isoCountries[isoCode].languages.map((language) => `${language}_${isoCode}`)
return isoCountries[isoCode].languages.map(
(language) => `${language}_${isoCode}`
)
})
)
)
Expand Down
189 changes: 96 additions & 93 deletions tests/getAsKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,101 @@ import { describe, expect } from '@jest/globals'
import { getAsKey } from '../src/'

describe('getAsKey', () => {
describe('getAsKey', () => {
it('should return an object with languages as keys', () => {
const result = getAsKey('language')
const expectedKeys = Object.keys(result)

expect(expectedKeys.length).toBeGreaterThan(10)
})

it('should return an object with names as keys', () => {
const result = getAsKey('name')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['Andorra', 'United Arab Emirates', 'Afghanistan'])
)
})

it('should return an object with locale as keys', () => {
const result = getAsKey('locale')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'ca_AD',
'ar_AE',
'ps_AF',
'uz_AF',
'tk_AF',
'en_AG',
'en_AI',
])
)
})

it('should return an object with language-code as keys', () => {
const result = getAsKey('language-code')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'ca-AD',
'uz-AF',
'tk-AF',
'en-AG',
'en-AI',
'sq-AL',
'hy-AM',
])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('iso')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR'])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('language-name')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(["Catalan; Valencian", "Arabic", "Pashto, Pushto", "Uzbek", "Turkmen", "English", "Albanian", "Armenian", "Russian", "Portuguese"])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('language-original')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(["Català", "العربية", "پښتو", "Türkmen, Түркмен", "English", "Shqip", "Հայերեն", "русский язык", "Português"])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('original')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'Andorra',
'دولة الإمارات العربية المتحدة',
'افغانستان',
'Antigua and Barbuda',
'Anguilla',
'Shqipëria',
])
)
})
it('should return an object with languages as keys', () => {
const result = getAsKey('language')
const expectedKeys = Object.keys(result)

expect(expectedKeys.length).toBeGreaterThan(10)
})

it('should return an object with names as keys', () => {
const result = getAsKey('name')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['Andorra', 'United Arab Emirates', 'Afghanistan'])
)
})

it('should return an object with locale as keys', () => {
const result = getAsKey('locale')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['ca_AD', 'ar_AE', 'ps_AF', 'uz_AF', 'tk_AF', 'en_AG', 'en_AI'])
)
})

it('should return an object with language-code as keys', () => {
const result = getAsKey('language-code')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['ca-AD', 'uz-AF', 'tk-AF', 'en-AG', 'en-AI', 'sq-AL', 'hy-AM'])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('iso')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR'])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('language-name')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'Catalan; Valencian',
'Arabic',
'Pashto, Pushto',
'Uzbek',
'Turkmen',
'English',
'Albanian',
'Armenian',
'Russian',
'Portuguese',
])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('language-original')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'Català',
'العربية',
'پښتو',
'Türkmen, Түркмен',
'English',
'Shqip',
'Հայերեն',
'русский язык',
'Português',
])
)
})

it('should return an object with original data as keys', () => {
const result = getAsKey('original')
const expectedKeys = Object.keys(result)

expect(expectedKeys).toEqual(
expect.arrayContaining([
'Andorra',
'دولة الإمارات العربية المتحدة',
'افغانستان',
'Antigua and Barbuda',
'Anguilla',
'Shqipëria',
])
)
})
})
3 changes: 2 additions & 1 deletion tests/getKeyValue .test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from '@jest/globals'
import { getKeyValue } from '../src/'
import { IsoDataType } from '../src/type'
import { IsoDataType } from '../src/types'


describe('getKeyValue', () => {
test.each([
Expand Down
38 changes: 19 additions & 19 deletions tests/getLanguageData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { getLanguageData } from '../src/'

describe('getLanguageData', () => {
it('should return language data for valid ISO code', () => {
const languageCode = 'en';
const expectedResult = { name: 'English', original: 'English' };
const languageCode = 'en'
const expectedResult = { name: 'English', original: 'English' }

const result = getLanguageData(languageCode);
expect(result).toEqual(expectedResult);
});
const result = getLanguageData(languageCode)
expect(result).toEqual(expectedResult)
})

it('should return language data for valid locale code', () => {
const languageCode = 'en-US';
const expectedResult = { name: 'English', original: 'English' };
const languageCode = 'en-US'
const expectedResult = { name: 'English', original: 'English' }

const result = getLanguageData(languageCode);
expect(result).toEqual(expectedResult);
});
const result = getLanguageData(languageCode)
expect(result).toEqual(expectedResult)
})

it('should return false for invalid language code', () => {
const languageCode = 'invalidCode';
const result = getLanguageData(languageCode);
expect(result).toBe(false);
});
const languageCode = 'invalidCode'
const result = getLanguageData(languageCode)
expect(result).toBe(false)
})

it('should return false for empty string', () => {
const languageCode = '';
const result = getLanguageData(languageCode);
expect(result).toBe(false);
});
});
const languageCode = ''
const result = getLanguageData(languageCode)
expect(result).toBe(false)
})
})
Loading

0 comments on commit 4031b81

Please sign in to comment.