Skip to content

Commit

Permalink
HTTP server + Actions integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
strayfade committed Feb 25, 2024
1 parent fcb176e commit b230946
Show file tree
Hide file tree
Showing 11 changed files with 7,672 additions and 1,736 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Jest
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '16'

# Speed up subsequent runs with caching
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# Install required deps for action
- name: Install Dependencies
run: npm install

# Finally, run our tests
- name: Run the tests
run: npm test
8 changes: 1 addition & 7 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,4 @@ const ErrorHandler = async (error, req, res, next) => {
App.use(ErrorLogger)
App.use(ErrorHandler)

// Start Server
let Port = process.env.PORT || parseInt(process.argv[2])
App.listen(Port, () => {
console.clear()
Log('Listening on port ' + Port)
Log('Link: http://localhost:' + Port)
})
module.exports = { App }
1 change: 1 addition & 0 deletions Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MakeFormat = () => {
return '[' + FormattingTag + ']'
}
const Log = (String) => {
// eslint-disable-next-line no-console
console.log(MakeFormat() + ' - ' + String.toString())
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ cd website

3. Install packages using the command `npm i`

4. Run the command `npm run prod` to start the server (this automatically builds static files and listens on port `3000`).
4. Run the command `npm run develop` to start the development server (this automatically builds static files and listens on a port).

5. Navigate to the site, hosted locally at [127.0.0.1:3000](http://127.0.0.1:3000) by default.
5. Navigate to the site
16 changes: 16 additions & 0 deletions Server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const http = require('http')
const { App } = require('./App')
const { Log } = require('./Log')

const Server = http.createServer(App)

Server.listen(process.env.PORT || parseInt(process.argv[2]) || '8000')

Server.on('listening', () => {
const Address = Server.address()
const Binding = typeof Address === 'string' ? `pipe ${Address}` : `port ${Address.port}`
Log(`Listening on ${Binding}`)
Log(`Local address (if available): http://127.0.0.1:${Address.port}`)
})

module.exports = { Server }
4 changes: 2 additions & 2 deletions generators/Assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const GeneratePageCached = async (
AvailablePages,
AvailablePageSelector,
Custom = '',
Filename,
Filename
) => {
let ServeInfo =
' (' +
Expand Down Expand Up @@ -471,7 +471,7 @@ const GeneratePage = async (
AvailablePages,
AvailablePageSelector,
Custom = '',
Filename = '_None.md',
Filename = '_None.md'
) => {
let HeadStr = await Head.GenerateHead(Article, Locale)
let BodyStr = await GenerateBodyV2(Article, Locale, AvailablePages, AvailablePageSelector, Custom, Filename)
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
setupFiles: ['<rootDir>/tests/env.js'],
}
Loading

0 comments on commit b230946

Please sign in to comment.