Skip to content

Commit

Permalink
Implement ?command=readdir tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StarLederer committed Mar 26, 2022
1 parent 20138f4 commit 9e1f55c
Show file tree
Hide file tree
Showing 11 changed files with 2,491 additions and 141 deletions.
1 change: 1 addition & 0 deletions __tests__/assets/directory/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file 1 content
Empty file added __tests__/assets/file
Empty file.
1 change: 1 addition & 0 deletions __tests__/assets/file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file 2 content
44 changes: 44 additions & 0 deletions __tests__/src/abstraction/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fetch from 'node-fetch';

import { UserOptions } from 'src/plugin/Options';
import FsServer from '../../../src/plugin/server';
import { resolveOptions } from '../../../src/plugin/Options';
// import fs from '../../src/abstraction';

let server: FsServer;

beforeAll(() => {
const options: UserOptions = {
rootDir: '__tests__/assets',
};
server = new FsServer(resolveOptions(options));
server.start(true);
});

afterAll((done) => {
server.stop();
done();
});

describe('readdir request of __tests__/assets', () => {
it('should return the correct file tree', async () => {
const response = await fetch('http://localhost:7070?command=readdir');
const data = await response.json() as string[];
expect(response.status).toEqual(200);
expect(data).toContain('file');
expect(data).toContain('file2');
expect(data).not.toContain('notfile');
});

it('should return correct file tree when ?withFileTypes=true', async () => {
const response = await fetch('http://localhost:7070?command=readdir&withFileTypes=true');
const data = await response.json() as { name: string; dir: boolean }[];
expect(response.status).toEqual(200);
expect(data).toEqual(expect.arrayContaining([
{ name: 'file', dir: false },
{ name: 'directory', dir: true },
]));
});
});

export default {};
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
};
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
},
"typesVersions": {
"*": {
"browser": ["./lib/abstraction/index.d.ts"]
"browser": [
"./lib/abstraction/index.d.ts"
]
}
},
"type": "module",
"scripts": {
"prepack": "pnpm run build && cp .gitignore .npmignore && cat .npmpack >> .npmignore",
"postpack": "rm .npmignore",
"dev": "pnpm run build -- --watch",
"build": "tsup"
"build": "tsup",
"test": "jest"
},
"engines": {
"node": ">=14"
Expand Down Expand Up @@ -57,26 +60,32 @@
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.1",
"@types/koa": "^2.13.4",
"@types/koa-bodyparser": "^4.3.7",
"@types/koa-cors": "^0.0.2",
"@types/koa-router": "^7.4.4",
"@types/koa__cors": "^3.1.1",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^14.0.1",
"eslint-plugin-import": "^2.25.2",
"jest": "^27.5.1",
"node-fetch": "2",
"rimraf": "^3.0.2",
"rollup": "^2.58.3",
"supertest": "^6.2.2",
"ts-jest": "^27.1.4",
"tsup": "^5.5.0",
"typescript": "^4.4.4",
"vite": "^2.8.6"
},
"dependencies": {
"@koa/cors": "^3.2.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"koa-cors": "^0.0.16",
"koa-router": "^10.1.1"
}
}
Loading

0 comments on commit 9e1f55c

Please sign in to comment.