mirror of
https://github.com/directus/directus.git
synced 2026-01-23 08:58:22 -05:00
Tests for listFolders, resolvePackage (#8356)
* listFolders test passing 100% coverage * added tmp package * listFolders test updated to use random temp folder * add package tmp to workspace * tmp as dev dependency * direct imports * resolve-packages passing 100% coverage * fixed tmpdir location in list-folders * Pin tmp Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
7
package-lock.json
generated
7
package-lock.json
generated
@@ -50344,7 +50344,7 @@
|
||||
"devDependencies": {
|
||||
"npm-run-all": "4.1.5",
|
||||
"rimraf": "3.0.2",
|
||||
"tmp": "0.0.33",
|
||||
"tmp": "0.2.1",
|
||||
"typescript": "4.4.3"
|
||||
}
|
||||
},
|
||||
@@ -52917,7 +52917,7 @@
|
||||
"npm-run-all": "4.1.5",
|
||||
"pino": "*",
|
||||
"rimraf": "3.0.2",
|
||||
"tmp": "0.0.33",
|
||||
"tmp": "0.2.1",
|
||||
"typescript": "4.4.3",
|
||||
"vue": "3",
|
||||
"vue-i18n": "9",
|
||||
@@ -52940,7 +52940,8 @@
|
||||
}
|
||||
},
|
||||
"tmp": {
|
||||
"version": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
|
||||
"integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
"devDependencies": {
|
||||
"npm-run-all": "4.1.5",
|
||||
"rimraf": "3.0.2",
|
||||
"tmp": "0.0.33",
|
||||
"tmp": "0.2.1",
|
||||
"typescript": "4.4.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { adjustDate } from '.';
|
||||
import { adjustDate } from './adjust-date';
|
||||
|
||||
describe('Adjust a given date by a given change in duration.', () => {
|
||||
const date = new Date('2021-09-20T21:06:51.517Z');
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { defineInterface, defineDisplay, defineModule, defineLayout, defineHook, defineEndpoint } from '.';
|
||||
import {
|
||||
defineInterface,
|
||||
defineDisplay,
|
||||
defineModule,
|
||||
defineLayout,
|
||||
defineHook,
|
||||
defineEndpoint,
|
||||
} from './define-extension';
|
||||
import { Type } from '../types/fields';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { filtersToQuery } from '.';
|
||||
import { filtersToQuery } from './filters-to-query';
|
||||
import { Filter } from '../types/filter';
|
||||
|
||||
describe('filtersToQuery', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getFieldsFromTemplate } from '.';
|
||||
import { getFieldsFromTemplate } from './get-fields-from-template';
|
||||
|
||||
describe('getFieldsFromTemplate', () => {
|
||||
it('returns an empty array when passed null', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getFilterOperatorsForType } from '.';
|
||||
import { getFilterOperatorsForType } from './get-filter-operators-for-type';
|
||||
import { TYPES } from '../constants/fields';
|
||||
|
||||
describe('', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getRelationType } from '.';
|
||||
import { getRelationType } from './get-relation-type';
|
||||
import { Relation } from '../types';
|
||||
|
||||
describe('getRelationType', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isExtension, isAppExtension, isApiExtension, isExtensionPackage } from '.';
|
||||
import { isExtension, isAppExtension, isApiExtension, isExtensionPackage } from './is-extension';
|
||||
|
||||
describe('is extension type', () => {
|
||||
it('returns true when passed a valid extension_type', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { moveInArray } from '.';
|
||||
import { moveInArray } from './move-in-array';
|
||||
|
||||
describe('moveInArray', () => {
|
||||
const testArray = [1, 2, 3, 4, 5, 6];
|
||||
|
||||
20
packages/shared/src/utils/node/list-folders.test.ts
Normal file
20
packages/shared/src/utils/node/list-folders.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { listFolders } from './list-folders';
|
||||
import { dirSync, SynchrounousResult } from 'tmp';
|
||||
|
||||
describe('', () => {
|
||||
let rootDir: SynchrounousResult;
|
||||
let childDir: SynchrounousResult;
|
||||
|
||||
beforeEach(() => {
|
||||
rootDir = dirSync({ unsafeCleanup: true, tmpdir: './' } as any);
|
||||
childDir = dirSync({ tmpdir: rootDir.name } as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rootDir.removeCallback();
|
||||
});
|
||||
it('returns all the subdirectories of the current directory', async () => {
|
||||
const childPath = childDir.name.split('/');
|
||||
expect(await listFolders(rootDir.name)).toStrictEqual([childPath[childPath?.length - 1]]);
|
||||
});
|
||||
});
|
||||
22
packages/shared/src/utils/node/resolve-package.test.ts
Normal file
22
packages/shared/src/utils/node/resolve-package.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { resolvePackage } from './resolve-package';
|
||||
import { dirSync, SynchrounousResult } from 'tmp';
|
||||
import { ensureDirSync, writeJsonSync } from 'fs-extra';
|
||||
import path from 'path';
|
||||
describe('', () => {
|
||||
let rootDir: SynchrounousResult;
|
||||
beforeEach(() => {
|
||||
rootDir = dirSync({ unsafeCleanup: true, tmpdir: './' } as any);
|
||||
ensureDirSync(`${rootDir.name}/node_modules/`);
|
||||
ensureDirSync(`${rootDir.name}/node_modules/test-package/`);
|
||||
writeJsonSync(`${rootDir.name}/node_modules/test-package/package.json`, { name: 'test' });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rootDir.removeCallback();
|
||||
});
|
||||
it('the package to be found', () => {
|
||||
expect(resolvePackage('test-package', rootDir.name)).toBe(
|
||||
path.resolve(`${rootDir.name}/node_modules/test-package`)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { parseFilter } from '.';
|
||||
import { parseFilter } from './parse-filter';
|
||||
import { Filter } from '../types/filter';
|
||||
|
||||
describe('', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pluralize, depluralize } from '.';
|
||||
import { pluralize, depluralize } from './pluralize';
|
||||
|
||||
describe('pluralize', () => {
|
||||
it('adds an s to the end of the string', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { toArray } from '.';
|
||||
import { toArray } from './to-array';
|
||||
|
||||
describe('toArray', () => {
|
||||
it('takes in a string and returns an array', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { validateExtensionManifest } from '.';
|
||||
import { validateExtensionManifest } from './validate-extension-manifest';
|
||||
|
||||
describe('', () => {
|
||||
it('returns false when passed item with is no name or version', () => {
|
||||
|
||||
Reference in New Issue
Block a user