Last active
November 26, 2025 03:48
-
-
Save bcomnes/df5dc907a9766f4c8dc581b86c34e317 to your computer and use it in GitHub Desktop.
README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| presets: [ | |
| '@babel/preset-env' // Transforms modern JS (including ESM) to CommonJS | |
| ], | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| transform: { | |
| // This tells Jest: "use babel-jest to transform any .mjs and .js files" | |
| '^.+\\.mjs$': 'babel-jest', | |
| '^.+\\.js$': 'babel-jest', | |
| }, | |
| transformIgnorePatterns: [ | |
| // By default, Jest ignores everything in node_modules | |
| // This pattern says: "ignore everything EXCEPT these ESM packages" | |
| '/node_modules/(?!(pg-boss|serialize-error)/).*/' | |
| ], | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "jest-test", | |
| "version": "0.0.0", | |
| "description": "", | |
| "license": "MIT", | |
| "author": "Bret Comnes <bcomnes@gmail.com> (https://bret.io/)", | |
| "type": "commonjs", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "jest" | |
| }, | |
| "devDependencies": { | |
| "@babel/core": "^7.28.5", | |
| "@babel/preset-env": "^7.28.5", | |
| "babel-jest": "^30.2.0", | |
| "jest": "^30.2.0" | |
| }, | |
| "dependencies": { | |
| "pg-boss": "12.3.0" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sum(a, b) { | |
| return a + b; | |
| } | |
| module.exports = sum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const sum = require('./sum'); | |
| const { PgBoss } = require('pg-boss') | |
| test('adds 1 + 2 to equal 3', () => { | |
| expect(sum(1, 2)).toBe(3); | |
| readme() | |
| .catch(err => { | |
| console.log(err) | |
| process.exit(1) | |
| }) | |
| }); | |
| async function readme() { | |
| const boss = new PgBoss('postgres://localhost/pgboss'); | |
| boss.on('error', console.error) | |
| await boss.start() | |
| const queue = 'readme-queue' | |
| await boss.createQueue(queue) | |
| const id = await boss.send(queue, { arg1: 'read me' }) | |
| console.log(`created job ${id} in queue ${queue}`) | |
| await boss.work(queue, async ([ job ]) => { | |
| console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`) | |
| }) | |
| } | |
| readme() | |
| .catch(err => { | |
| console.log(err) | |
| process.exit(1) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment