这是indexloc提供的服务,不要输入任何密码
Skip to content

Configure Jest (#31) #43

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

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,9 @@
# Env Vars #
############
env:
browser: true
es6: true
jest: true
node: true

###############
# Global Vars #
###############
globals:
# Atomics: readonly
# SharedArrayBuffer: readonly
CacheService: readonly
CalendarApp: readonly
CardService: readonly
ContentService: readonly
Docs: readonly
DocumentApp: readonly
DriveApp: readonly
FormApp: readonly
GmailApp: readonly
HtmlService: readonly
Logger: readonly
MailApp: readonly
PropertiesService: readonly
ScriptApp: readonly
Session: readonly
SitesApp: readonly
SlidesApp: readonly
SpreadsheetApp: readonly
UrlFetchApp: readonly
Utilities: readonly
XmlService: readonly

###############
# Parser vars #
###############
Expand All @@ -58,6 +28,7 @@ extends:
- 'plugin:prettier/recommended'
plugins:
- '@typescript-eslint'
- 'jest'
#########
# Rules #
#########
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ node_modules/

# System files
.DS_Store

# Jest
coverage/
20 changes: 20 additions & 0 deletions __tests__/getBytes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getBlobBytes } from '../src/sheetsl';

Utilities.newBlob = jest.fn((text: string) => ({
getBytes: jest.fn(() => ({
length: text.length,
})),
})) as any;

const patterns = [
{
input: 'test string',
expectedOutput: 11,
},
];

describe.each(patterns)('getBlobBytes', ({ input, expectedOutput }) => {
test(`getBlobBytes test: ${input}`, () => {
expect(getBlobBytes(input)).toBe(expectedOutput);
});
});
27 changes: 27 additions & 0 deletions __tests__/getDeepLApiBaseUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
DEEPL_API_BASE_URL_FREE,
DEEPL_API_BASE_URL_PRO,
getDeepLApiBaseUrl,
} from '../src/sheetsl';

const patterns = [
{
title: 'DeepL API Free account',
input: 'xxxxxxxxxxx:fx',
expectedOutput: DEEPL_API_BASE_URL_FREE,
},
{
title: 'DeepL API Pro account',
input: 'xxxxxxxxxxx',
expectedOutput: DEEPL_API_BASE_URL_PRO,
},
];

describe.each(patterns)(
'getDeepLApiBaseUrl',
({ title, input, expectedOutput }) => {
test(`getDeepLApiBaseUrl test: ${title}`, () => {
expect(getDeepLApiBaseUrl(input)).toBe(expectedOutput);
});
}
);
29 changes: 29 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
globals: {
/*
'ts-jest': {
diagnostics: false,
},*/
PropertiesService: {},
UrlFetchApp: {},
Utilities: {},
},
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['js', 'ts', 'tsx', 'json'],
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.[jt]s?(x)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
verbose: true,
};
Loading