Skip to content

Commit

Permalink
テスト実行環境Docker関連ファイルと単体テスト例 (VOICEVOX#291)
Browse files Browse the repository at this point in the history
* テスト実行環境DockerファイルとStore/Vue.js createStoreのテスト

* Add rust and cargo into dockerfile

* Import path refine
  • Loading branch information
yuki1229ushioda authored Oct 4, 2021
1 parent 9a405fe commit 9eaad39
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:14.17.4

WORKDIR /opt
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup_install.sh
RUN chmod 755 rustup_install.sh
RUN echo 1 | sh rustup_install.sh -y
ENV PATH="/root/.cargo/bin:$PATH"
RUN cargo install typos-cli
COPY . /work
WORKDIR /work
RUN npm ci
EXPOSE 3000

CMD ["/bin/sh"]
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
test:
build: .
working_dir: /work
# If you don't have node_modules, use "npm ci", install node_modules into the yor directory.
# Use command bellow
# `docker-compose up -d --build`
# The container will stop automatically after install
# If you have node_modules already, you comment out '# command: "npm ci"'

# command: "npm ci"


# After node_modules install, use command bellow to exec "/bin/sh" and the container will remain.
# `docker-compose up -d`
# To access container, use command bellow
# `docker exec -it voicevox_test_1 /bin/bash`

# command: "/bin/sh"


# If you want test automatically (test runs when you save any files), use this command property and view logs
# Use Command bellow
# `docker logs --tail 1000 -f voicevox_test_1`

command: "npm run test-watch:unit "
ports:
- 3000:3000
volumes:
- .:/work:cache
tty: true
stdin_open: true
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test-watch:unit": "vue-cli-service test:unit --watch",
"test:e2e": "vue-cli-service test:e2e",
"test-watch:e2e": "vue-cli-service test:e2e --watch",
"lint": "vue-cli-service lint --no-fix",
"markdownlint": "markdownlint *.md",
"fmt": "vue-cli-service lint",
Expand Down
101 changes: 101 additions & 0 deletions tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { createLogger } from "vuex";
import { indexStore } from "@/store/index";
import { createStore } from "@/store/vuex";
import { AllActions, AllGetters, AllMutations, State } from "@/store/type";
import { commandStore } from "@/store/command";
import { audioStore, audioCommandStore } from "@/store/audio";
import { projectStore } from "@/store/project";
import { uiStore } from "@/store/ui";
import { settingStore } from "@/store/setting";
import { assert } from "chai";
const isDevelopment = process.env.NODE_ENV == "development";
// TODO: Swap external files to Mock

describe("store/vuex.js test", () => {
it("creaete store", () => {
const store = createStore<State, AllGetters, AllActions, AllMutations>({
state: {
engineState: "STARTING",
audioItems: {},
audioKeys: [],
audioStates: {},
uiLockCount: 0,
audioDetailPaneOffset: undefined,
audioInfoPaneOffset: undefined,
nowPlayingContinuously: false,
undoCommands: [],
redoCommands: [],
useUndoRedo: isDevelopment,
useGpu: false,
isHelpDialogOpen: false,
isSettingDialogOpen: false,
isMaximized: false,
savingSetting: {
fileEncoding: "UTF-8",
fixedExportEnabled: false,
fixedExportDir: "",
avoidOverwrite: false,
},
isPinned: false,
},
getters: {
...uiStore.getters,
...audioStore.getters,
...commandStore.getters,
...projectStore.getters,
...settingStore.getters,
...audioCommandStore.getters,
...indexStore.getters,
},
mutations: {
...uiStore.mutations,
...audioStore.mutations,
...commandStore.mutations,
...projectStore.mutations,
...settingStore.mutations,
...audioCommandStore.mutations,
...indexStore.mutations,
},
actions: {
...uiStore.actions,
...audioStore.actions,
...commandStore.actions,
...projectStore.actions,
...settingStore.actions,
...audioCommandStore.actions,
...indexStore.actions,
},
plugins: isDevelopment ? [createLogger()] : undefined,
strict: process.env.NODE_ENV !== "production",
});
assert.exists(store);
assert.isObject(store);
assert.isObject(store.state);
assert.equal(store.state.engineState, "STARTING");
assert.isObject(store.state.audioItems);
assert.isEmpty(store.state.audioItems);
assert.isArray(store.state.audioKeys);
assert.isEmpty(store.state.audioKeys);
assert.isObject(store.state.audioStates);
assert.isEmpty(store.state.audioStates);
assert.equal(store.state.uiLockCount, 0);
assert.isUndefined(store.state.audioDetailPaneOffset);
assert.isUndefined(store.state.audioInfoPaneOffset);
assert.equal(store.state.nowPlayingContinuously, false);
assert.isArray(store.state.undoCommands);
assert.isEmpty(store.state.undoCommands);
assert.isArray(store.state.redoCommands);
assert.isEmpty(store.state.redoCommands);
assert.equal(store.state.useUndoRedo, false);
assert.equal(store.state.useGpu, false);
assert.equal(store.state.isHelpDialogOpen, false);
assert.equal(store.state.isSettingDialogOpen, false);
assert.equal(store.state.isMaximized, false);
assert.isObject(store.state.savingSetting);
assert.propertyVal(store.state.savingSetting, "fileEncoding", "UTF-8");
assert.propertyVal(store.state.savingSetting, "fixedExportEnabled", false);
assert.propertyVal(store.state.savingSetting, "fixedExportDir", "");
assert.propertyVal(store.state.savingSetting, "avoidOverwrite", false);
assert.equal(store.state.isPinned, false);
});
});

0 comments on commit 9eaad39

Please sign in to comment.