From 684746b6674668231f46e57ada954ff2efe3d0ad Mon Sep 17 00:00:00 2001 From: Andrii Bodnar Date: Mon, 24 Jul 2023 12:47:36 +0300 Subject: [PATCH] remove js files --- __tests__/utils/path.test.js | 35 ----------- __tests__/utils/zip.test.js | 49 --------------- __tests__/writer.test.js | 114 ----------------------------------- 3 files changed, 198 deletions(-) delete mode 100644 __tests__/utils/path.test.js delete mode 100644 __tests__/utils/zip.test.js delete mode 100644 __tests__/writer.test.js diff --git a/__tests__/utils/path.test.js b/__tests__/utils/path.test.js deleted file mode 100644 index a84e0ed..0000000 --- a/__tests__/utils/path.test.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = require("../../src/utils/path"); -const globals_1 = require("@jest/globals"); -globals_1.jest.mock('axios'); -globals_1.jest.mock('fs'); -(0, globals_1.describe)('utils', () => { - (0, globals_1.describe)('generateRelativeFileLink', () => { - (0, globals_1.it)('should generate the relative file link between two file paths', () => { - const currentFilePath = '/path/to/current/file.ts'; - const destinationFilePath = '/path/to/destination/file.ts'; - const expectedRelativeLink = '../destination/file.ts'; - const relativeLink = (0, path_1.generateRelativeFileLink)(currentFilePath, destinationFilePath); - (0, globals_1.expect)(relativeLink).toEqual(expectedRelativeLink); - }); - }); - (0, globals_1.describe)('baseName', () => { - (0, globals_1.it)('should return the base name of the file path', () => { - const filePath = '/path/to/some/file.txt'; - const expectedBaseName = 'file.txt'; - const result = (0, path_1.baseName)(filePath); - (0, globals_1.expect)(result).toEqual(expectedBaseName); - }); - (0, globals_1.it)('should return the full path if the file path is just a basename', () => { - const filePath = 'file.txt'; - const result = (0, path_1.baseName)(filePath); - (0, globals_1.expect)(result).toEqual(filePath); - }); - (0, globals_1.it)('should return an empty string for an empty path', () => { - const filePath = ''; - const result = (0, path_1.baseName)(filePath); - (0, globals_1.expect)(result).toEqual(''); - }); - }); -}); diff --git a/__tests__/utils/zip.test.js b/__tests__/utils/zip.test.js deleted file mode 100644 index cd5b9d7..0000000 --- a/__tests__/utils/zip.test.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __importDefault(require("fs")); -const adm_zip_1 = __importDefault(require("adm-zip")); -const zip_1 = require("../../src/utils/zip"); -const globals_1 = require("@jest/globals"); -const axios_1 = __importDefault(require("axios")); -globals_1.jest.mock('axios'); -globals_1.jest.mock('fs'); -globals_1.jest.mock('adm-zip'); -(0, globals_1.describe)('zip', () => { - (0, globals_1.describe)('downloadZipAndUnzip', () => { - (0, globals_1.it)('should download a zip file, extract its contents, and return entries', () => __awaiter(void 0, void 0, void 0, function* () { - const zipUrl = 'https://example.com/translations.zip'; - const destination = '/path/to/destination'; - const zipFilePath = `Translations-${Date.now()}.zip`; - const responseData = Buffer.from('zip_file_data_here'); - const expectedEntries = ['file1.txt', 'file2.txt']; - axios_1.default.get.mockResolvedValue({ data: responseData }); - const unlinkSyncMock = globals_1.jest.spyOn(fs_1.default, 'unlinkSync'); - const extractAllToMock = globals_1.jest.fn(); - const getEntriesMock = globals_1.jest.fn().mockReturnValueOnce([{ entryName: 'file1.txt' }, { entryName: 'file2.txt' }]); - adm_zip_1.default.mockImplementation(() => ({ - extractAllTo: extractAllToMock, - getEntries: getEntriesMock - })); - const entries = yield (0, zip_1.downloadZipAndUnzip)(zipUrl, destination); - // eslint-disable-next-line @typescript-eslint/unbound-method - (0, globals_1.expect)(axios_1.default.get).toHaveBeenCalledWith(zipUrl, { responseType: 'arraybuffer' }); - (0, globals_1.expect)(adm_zip_1.default).toHaveBeenCalledWith(zipFilePath); - (0, globals_1.expect)(extractAllToMock).toHaveBeenCalledWith(destination, true); - (0, globals_1.expect)(getEntriesMock).toHaveBeenCalled(); - (0, globals_1.expect)(unlinkSyncMock).toHaveBeenCalledWith(zipFilePath); - (0, globals_1.expect)(entries).toEqual(expectedEntries); - })); - }); -}); diff --git a/__tests__/writer.test.js b/__tests__/writer.test.js deleted file mode 100644 index cc6c735..0000000 --- a/__tests__/writer.test.js +++ /dev/null @@ -1,114 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __importDefault(require("fs")); -const writer_1 = require("../src/writer"); -const globals_1 = require("@jest/globals"); -globals_1.jest.mock('fs'); -(0, globals_1.describe)('Writer', () => { - const credentials = { token: 'API_TOKEN', projectId: 1 }; - const config = { languageSwitcher: true, destination: 'docs', file: 'README.md' }; - const logger = { - log: globals_1.jest.fn() - }; - let writer; - (0, globals_1.beforeEach)(() => { - globals_1.jest.resetAllMocks(); - writer = new writer_1.Writer(credentials, config, logger); - writer.setProjectLanguages([ - { - id: 'fr', - name: 'French', - locale: 'fr', - editorCode: 'fr', - twoLettersCode: 'fr', - threeLettersCode: 'fra', - androidCode: 'fr', - osxCode: 'fr', - osxLocale: 'fr', - pluralCategoryNames: ['one', 'other'], - pluralRules: 'nplurals=2; plural=(n > 1);', - pluralExamples: ['1', '0'], - textDirection: 'ltr', - dialectOf: 'fr' - }, - { - id: 'uk', - name: 'Ukrainian', - locale: 'uk', - editorCode: 'uk', - twoLettersCode: 'uk', - threeLettersCode: 'ukr', - androidCode: 'uk', - osxCode: 'uk', - osxLocale: 'uk', - pluralCategoryNames: ['one', 'few', 'many', 'other'], - pluralRules: 'rules_placeholder', - pluralExamples: ['1', '0', '5', '11'], - textDirection: 'ltr', - dialectOf: '' - } - ]); - }); - (0, globals_1.describe)('addLanguageSwitcher', () => { - (0, globals_1.it)('should skip adding language switcher if placeholders are missing in the file', () => __awaiter(void 0, void 0, void 0, function* () { - const file = '/path/to/README.md'; - const mockFileContents = 'Some content without placeholders'; - fs_1.default.readFileSync.mockReturnValueOnce(mockFileContents); - yield writer.addLanguageSwitcher(file); - // eslint-disable-next-line @typescript-eslint/unbound-method - (0, globals_1.expect)(logger.log).toHaveBeenCalledWith('warning', `Skipped! Please add ${writer['placeholderStart']} and ${writer['placeholderEnd']} to your README.md`); - // Ensure the file contents are not modified - (0, globals_1.expect)(fs_1.default.writeFileSync).not.toHaveBeenCalled(); - })); - (0, globals_1.it)('should add language switcher to the file with correct contents', () => __awaiter(void 0, void 0, void 0, function* () { - const file = 'README.md'; - const mockFileContents = ` -Some content before - - -Some content after -`; - const expectedSwitcher = '[English](docs/README.en.md) | [French](docs/README.fr.md)'; - fs_1.default.readFileSync.mockReturnValueOnce(mockFileContents); - writer.projectLanguages = [ - { name: 'English', locale: 'en' }, - { name: 'French', locale: 'fr' } - ]; - yield writer.addLanguageSwitcher(file); - const expectedUpdatedFileContents = ` -Some content before - -${expectedSwitcher} - -Some content after -`; - (0, globals_1.expect)(fs_1.default.writeFileSync).toHaveBeenCalledWith(file, expectedUpdatedFileContents); - })); - }); - (0, globals_1.describe)('renderSwitcher', () => { - (0, globals_1.it)('should render the language switcher correctly', () => __awaiter(void 0, void 0, void 0, function* () { - const file = 'README.md'; - const switcher = yield writer.renderSwitcher(file); - const expectedSwitcher = '[French](docs/README.fr.md) | [Ukrainian](docs/README.uk.md)'; - (0, globals_1.expect)(switcher).toEqual(expectedSwitcher); - })); - (0, globals_1.it)('should not render a link for the current language', () => __awaiter(void 0, void 0, void 0, function* () { - const file = 'README.fr.md'; - const switcher = yield writer.renderSwitcher(file); - const expectedSwitcher = '**French** | [Ukrainian](docs/README.uk.md)'; - (0, globals_1.expect)(switcher).toEqual(expectedSwitcher); - })); - }); -});