Skip to content

Commit

Permalink
unit tests might work now
Browse files Browse the repository at this point in the history
  • Loading branch information
a1cd committed Jul 4, 2024
1 parent 61f12f4 commit f20f971
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 30 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Unit Testing (ViTest)

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and run Docker Compose
run: |
docker-compose up -d testserver
docker-compose exec testserver npm run test run
docker-compose down
61 changes: 54 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ ENV NODE_TLS_REJECT_UNAUTHORIZED 0
RUN NODE_TLS_REJECT_UNAUTHORIZED=0
COPY .npmrc .
COPY package.json .
RUN ["bun", "install", "--ignore-scripts", "--no-progress"]
RUN ["bun", "install", "--ignore-scripts", "--no-progress", "--development"]

FROM bun-install AS bun-prepare

COPY .npmrc .

#COPY package-lock.json .

COPY package.json .
COPY tsconfig.json .
COPY package.json ./package.json
COPY tsconfig.json ./tsconfig.json

COPY nuxt.config.ts ./nuxt.config.ts
COPY app.config.ts ./app.config.ts

COPY nuxt.config.ts .
COPY app.config.ts .
COPY vitest.config.ts ./vitest.config.ts

FROM bun-prepare AS files

COPY app.vue .

COPY ./pages ./pages
COPY ./public ./public
COPY ./server ./server
Expand All @@ -92,11 +95,55 @@ COPY ./utils ./utils
COPY ./plugins ./plugins
COPY ./service-worker ./service-worker
COPY ./composables ./composables
COPY vitest.config.ts .

#ENTRYPOINT ["bash"]
COPY ./tests ./tests

COPY ./app.vue .

RUN ["bun", "--bun", "run", "postinstall"]

RUN bun i --development

FROM node:lts AS test

WORKDIR /usr/src/nuxt3-app

ENV NODE_ENV development


COPY --from=files /usr/src/nuxt3-app/pages ./pages
COPY --from=files /usr/src/nuxt3-app/public ./public
COPY --from=files /usr/src/nuxt3-app/server ./server
COPY --from=files /usr/src/nuxt3-app/components ./components
COPY --from=files /usr/src/nuxt3-app/utils ./utils
COPY --from=files /usr/src/nuxt3-app/plugins ./plugins
COPY --from=files /usr/src/nuxt3-app/service-worker ./service-worker
COPY --from=files /usr/src/nuxt3-app/composables ./composables
COPY --from=files /usr/src/nuxt3-app/tests ./tests
COPY --from=files /usr/src/nuxt3-app/node_modules ./node_modules
COPY --from=files /usr/src/nuxt3-app/.nuxt ./.nuxt

COPY --from=files /usr/src/nuxt3-app/.npmrc .

COPY --from=files /usr/src/nuxt3-app/package.json .
COPY --from=files /usr/src/nuxt3-app/tsconfig.json .

COPY --from=files /usr/src/nuxt3-app/nuxt.config.ts .
COPY --from=files /usr/src/nuxt3-app/app.config.ts .
COPY --from=files /usr/src/nuxt3-app/app.vue .

COPY --from=files /usr/src/nuxt3-app/vitest.config.ts .

RUN npm install @vitest/ui
ENTRYPOINT ["sleep", "10000"]
#or any similar command that does nothing but forces itself to stay open

FROM files AS listdir

RUN rm -rf ./node_modules;

RUN ls -AR;

FROM files AS build
ENV NODE_ENV development

Expand Down
Binary file removed bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ services:
couchDBHostname: couchdb
networks:
- intercom_network
testserver:
restart: on-failure
build:
context: .
dockerfile: Dockerfile
target: test
depends_on:
couchdb:
condition: service_healthy
couch-db-setup:
condition: service_completed_successfully
ports:
- "3000:3000"
links:
- couchdb:couchdb
environment:
couchDBHostname: couchdb
networks:
- intercom_network
devserver:
restart: on-failure
build:
Expand Down
11 changes: 11 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'


// https://github.com/nuxt/ui/issues/809
import { createRequire } from 'node:module'
const _require = createRequire(import.meta.url)
const defaultColors = _require('tailwindcss/colors.js')
delete defaultColors.lightBlue
delete defaultColors.warmGray
delete defaultColors.trueGray
delete defaultColors.coolGray
delete defaultColors.blueGray

var sw = true;
export default defineNuxtConfig({
modules: [
Expand Down
17 changes: 0 additions & 17 deletions nuxt.run.xml

This file was deleted.

8 changes: 4 additions & 4 deletions tests/pages/login.nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import App from "~/app.vue";
import {HTMLInputElement} from "happy-dom";

it('renders without crashing', async () => {
await renderSuspended(App, {route: '/login'});
expect(screen.findByText("Login")).toBeDefined
renderSuspended(App, {route: '/login'});
expect(screen.findByText("Login")).toBeDefined()
})

it('username area exists and is a textbox', async () => {
await renderSuspended(App, {route: '/login'})
renderSuspended(App, {route: '/login'})

const usernameBox = await screen.findByTestId("username");
expect(usernameBox).to.exist
expect(usernameBox).to.be.an.instanceOf(HTMLInputElement.prototype.constructor)
})

it('passwords area exists and is a textbox', async () => {
await renderSuspended(App, {route: '/login'})
renderSuspended(App, {route: '/login'})

const usernameBox = await screen.findByTestId("password");
expect(usernameBox).to.exist
Expand Down
7 changes: 5 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default defineVitestConfig({
indexedDb: true,
}
}
}
}
},
testTimeout: 300,
},
mode: "test",
logLevel: "info"
})

0 comments on commit f20f971

Please sign in to comment.