Skip to content

Commit

Permalink
Merge pull request #967 from tsg-ut/make-tests-pass-in-codespaces
Browse files Browse the repository at this point in the history
Make unit tests pass in codespaces
  • Loading branch information
hakatashi authored Nov 27, 2024
2 parents 4df80f9 + 862267a commit 1b80989
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
"settings": {
"files.autoSave": "off",
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.fixAll.eslint": "always"
},
"eslint.format.enable": true
"eslint.format.enable": true,
"typescript.format.enable": false,
"javascript.format.enable": false
},
"extensions": [
"ms-vscode.vscode-typescript-next",
Expand Down
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"<node_internals>/**"
],
"console": "internalConsole",
"outputCapture": "std"
"outputCapture": "std",
"env": {
"NODE_OPTIONS": "--max-old-space-size=4096"
}
}
],
"inputs": [
Expand Down
12 changes: 12 additions & 0 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ fs.promises.readFile = jest.fn((...args) => {
}
});

fs.promises.readdir = jest.fn((...args) => {
const [path] = args;
const fullPath = Path.resolve(process.cwd(), path);
const files = Object.keys(fs.virtualFiles).filter((file) => file.startsWith(fullPath));

if (files.length > 0) {
return new Promise((resolve) => resolve(files.map((file) => Path.basename(file))));
} else {
return realFs.promises.readdir(...args);
}
});

fs.access = jest.fn((...args) => {
const [path, , callback] = args;
const fullPath = Path.resolve(process.cwd(), path);
Expand Down
4 changes: 4 additions & 0 deletions auto-archiver/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ describe('auto-archiver', () => {
});

it('should archive channel if user responded with "stop"', async () => {
const FAKE_TOKEN = 'xoxt-1234-5678-91011';
process.env.HAKATASHI_TOKEN = FAKE_TOKEN;

const slack = new Slack();

const mockedAction = slack.messageClient.action as jest.MockedFunction<typeof slack.messageClient.action>;
Expand Down Expand Up @@ -226,6 +229,7 @@ describe('auto-archiver', () => {
expect((blocks[1] as SectionBlock).text.text).toBe('<@U12345678>の回答: *使用しない*');
expect(slack.webClient.conversations.archive).toBeCalledWith({
channel: FAKE_CHANNEL,
token: FAKE_TOKEN,
});
});

Expand Down
10 changes: 10 additions & 0 deletions shogi/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

jest.mock('cloudinary');
jest.mock('sqlite');
jest.mock('sqlite3', () => ({
Database: jest.fn(),
}));
jest.mock('fs');

const fs = require('fs');
const path = require('path');
const cloudinary = require('cloudinary');
const sqlite = require('sqlite');
const {default: Slack} = require('../lib/slackMock.ts');
const shogi = require('./index.js');

fs.virtualFiles = {
[path.join(__dirname, 'boards', 'hoge.sqlite3')]: '',
};

let slack = null;

beforeEach(() => {
Expand Down

0 comments on commit 1b80989

Please sign in to comment.