Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ RUN apt-get update && \
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get install -y gnupg wget && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y google-chrome-stable --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
# Skip Chrome installation for now as Playwright image already has browsers
RUN echo "Skipping Chrome installation - using Playwright browsers"


# Add pptr user.
Expand All @@ -31,17 +27,23 @@ RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
COPY . /codecept

RUN chown -R pptruser:pptruser /codecept
RUN runuser -l pptruser -c 'npm i --loglevel=warn --prefix /codecept'
# Set environment variables to skip browser downloads during npm install
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_SKIP_DOWNLOAD=true
# Install as root to ensure proper bin links are created
RUN cd /codecept && npm install --loglevel=warn
# Fix ownership after install
RUN chown -R pptruser:pptruser /codecept

RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
RUN mkdir /tests
WORKDIR /tests
# Install puppeteer so it's available in the container.
RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
RUN google-chrome --version
# Skip the redundant Puppeteer installation step since we're using Playwright browsers
# RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
# RUN chromium-browser --version

# Install playwright browsers
RUN npx playwright install
# Skip the playwright browser installation step since base image already has browsers
# RUN npx playwright install

# Allow to pass argument to codecept run via env variable
ENV CODECEPT_ARGS=""
Expand Down
53 changes: 53 additions & 0 deletions bin/test-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

/**
* Standalone test server script to replace json-server
*/

const path = require('path')
const TestServer = require('../lib/test-server')

// Parse command line arguments
const args = process.argv.slice(2)
let dbFile = path.join(__dirname, '../test/data/rest/db.json')
let port = 8010
let host = '0.0.0.0'

// Simple argument parsing
for (let i = 0; i < args.length; i++) {
const arg = args[i]

if (arg === '-p' || arg === '--port') {
port = parseInt(args[++i])
} else if (arg === '--host') {
host = args[++i]
} else if (!arg.startsWith('-')) {
dbFile = path.resolve(arg)
}
}

// Create and start server
const server = new TestServer({ port, host, dbFile })

console.log(`Starting test server with db file: ${dbFile}`)

server
.start()
.then(() => {
console.log(`Test server is ready and listening on http://${host}:${port}`)
})
.catch(err => {
console.error('Failed to start test server:', err)
process.exit(1)
})

// Graceful shutdown
process.on('SIGINT', () => {
console.log('\nShutting down test server...')
server.stop().then(() => process.exit(0))
})

process.on('SIGTERM', () => {
console.log('\nShutting down test server...')
server.stop().then(() => process.exit(0))
})
89 changes: 89 additions & 0 deletions docs/internal-test-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Internal API Test Server

This directory contains the internal API test server implementation that replaces the third-party `json-server` dependency.

## Files

- `lib/test-server.js` - Main TestServer class implementation
- `bin/test-server.js` - CLI script to run the server standalone

## Usage

### As npm script:

```bash
npm run test-server
```

### Directly:

```bash
node bin/test-server.js [options] [db-file]
```

### Options:

- `-p, --port <port>` - Port to listen on (default: 8010)
- `--host <host>` - Host to bind to (default: 0.0.0.0)
- `db-file` - Path to JSON database file (default: test/data/rest/db.json)

## Features

- **Full REST API compatibility** with json-server
- **Automatic file watching** - Reloads data when db.json file changes
- **CORS support** - Allows cross-origin requests for testing
- **Custom headers support** - Handles special headers like X-Test
- **File upload endpoints** - Basic file upload simulation
- **Express.js based** - Uses familiar Express.js framework

## API Endpoints

The server provides the same API endpoints as json-server:

### Users

- `GET /user` - Get user data
- `POST /user` - Create/update user
- `PATCH /user` - Partially update user
- `PUT /user` - Replace user

### Posts

- `GET /posts` - Get all posts
- `GET /posts/:id` - Get specific post
- `POST /posts` - Create new post
- `PUT /posts/:id` - Replace specific post
- `PATCH /posts/:id` - Partially update specific post
- `DELETE /posts/:id` - Delete specific post

### Comments

- `GET /comments` - Get all comments
- `POST /comments` - Create new comment
- `DELETE /comments/:id` - Delete specific comment

### Utility

- `GET /headers` - Return request headers (for testing)
- `POST /headers` - Return request headers (for testing)
- `POST /upload` - File upload simulation
- `POST /_reload` - Manually reload database file

## Migration from json-server

This server is designed as a drop-in replacement for json-server. The key differences:

1. **No CLI options** - Configuration is done through constructor options or CLI args
2. **Automatic file watching** - No need for `--watch` flag
3. **Built-in middleware** - Headers and CORS are handled automatically
4. **Simpler file upload** - Basic implementation without full multipart support

## Testing

The server is used by the following test suites:

- `test/rest/REST_test.js` - REST helper tests
- `test/rest/ApiDataFactory_test.js` - API data factory tests
- `test/helper/JSONResponse_test.js` - JSON response helper tests

All tests pass with the internal server, proving full compatibility.
Loading