refactor: @flecks/headless

This commit is contained in:
cha0s 2024-02-14 21:41:30 -06:00
parent b5b53b8f22
commit a2dc5e3788
10 changed files with 286 additions and 124 deletions

View File

@ -14,6 +14,7 @@
- '($1#L$2)'
'@flecks/electron': {}
'@flecks/fleck': {}
'@flecks/headless': {}
'@flecks/passport': {}
'@flecks/passport-local': {}
'@flecks/passport-local-react': {}

214
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@flecks/monorepo",
"version": "3.0.0",
"version": "4.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@flecks/monorepo",
"version": "3.0.0",
"version": "4.0.0",
"workspaces": [
"packages/*"
],
@ -2067,6 +2067,10 @@
"resolved": "packages/fleck",
"link": true
},
"node_modules/@flecks/headless": {
"resolved": "packages/headless",
"link": true
},
"node_modules/@flecks/passport": {
"resolved": "packages/passport",
"link": true
@ -16665,7 +16669,7 @@
},
"packages/build": {
"name": "@flecks/build",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.12.10",
@ -16676,7 +16680,7 @@
"@babel/preset-env": "^7.12.11",
"@babel/traverse": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"babel-loader": "^9.1.3",
"babel-merge": "^3.0.0",
"chai": "4.2.0",
@ -16734,7 +16738,7 @@
},
"packages/core": {
"name": "@flecks/core",
"version": "4.1.1",
"version": "4.2.0",
"license": "MIT",
"dependencies": {
"callsites": "^3.1.0",
@ -16790,10 +16794,10 @@
},
"packages/create-app": {
"name": "@flecks/create-app",
"version": "4.0.8",
"version": "4.0.9",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"commander": "11.1.0",
"validate-npm-package-name": "^3.0.0"
},
@ -16801,8 +16805,8 @@
"create-app": "build/cli.js"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/create-app/node_modules/builtins": {
@ -16820,45 +16824,45 @@
},
"packages/create-fleck": {
"name": "@flecks/create-fleck",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"commander": "11.1.0"
},
"bin": {
"create-fleck": "build/cli.js"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/db": {
"name": "@flecks/db",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"sequelize": "^6.3.5",
"sqlite3": "^5.0.2"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/docker": {
"name": "@flecks/docker",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"debug": "^4.3.3"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/docker/node_modules/debug": {
@ -16879,47 +16883,47 @@
},
"packages/dox": {
"name": "@flecks/dox",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.17.2",
"@babel/traverse": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"comment-parser": "^1.3.0",
"rimraf": "^5.0.5"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/electron": {
"name": "@flecks/electron",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"electron": "^28.1.4",
"electron-devtools-installer": "^3.2.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/fleck": {
"name": "@flecks/fleck",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"babel-merge": "^3.0.0",
"debug": "^4.3.3",
"mocha": "^10.2.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/build": "^4.1.0",
"chai": "4.2.0"
}
},
@ -16939,77 +16943,87 @@
}
}
},
"packages/headless": {
"version": "4.0.0",
"dependencies": {
"@flecks/core": "^4.0.0"
},
"devDependencies": {
"@flecks/build": "^4.0.0",
"@flecks/fleck": "^4.0.0"
}
},
"packages/passport": {
"name": "@flecks/passport",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/db": "^4.0.7",
"@flecks/redux": "^4.0.7",
"@flecks/session": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/db": "^4.1.0",
"@flecks/redux": "^4.0.8",
"@flecks/session": "^4.0.8",
"passport": "^0.7.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/passport-local": {
"name": "@flecks/passport-local",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/passport": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/passport": "^4.0.8",
"bcrypt": "^5.1.1",
"passport-local": "^1.0.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/passport-local-react": {
"name": "@flecks/passport-local-react",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/passport-local": "^4.0.7",
"@flecks/passport-react": "^4.0.7",
"@flecks/react": "^4.0.7"
"@flecks/core": "^4.2.0",
"@flecks/passport-local": "^4.0.8",
"@flecks/passport-react": "^4.0.8",
"@flecks/react": "^4.0.8"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/passport-react": {
"name": "@flecks/passport-react",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/passport": "^4.0.7",
"@flecks/react": "^4.0.7",
"@flecks/react-redux": "^4.0.7",
"@flecks/web": "^4.0.7"
"@flecks/core": "^4.2.0",
"@flecks/passport": "^4.0.8",
"@flecks/react": "^4.0.8",
"@flecks/react-redux": "^4.0.8",
"@flecks/web": "^4.1.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/react": {
"name": "@flecks/react",
"version": "4.0.7",
"version": "4.0.8",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"@babel/preset-react": "^7.23.3",
"@flecks/core": "^4.1.1",
"@flecks/web": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/web": "^4.1.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"babel-merge": "^3.0.0",
"classnames": "^2.3.1",
@ -17025,55 +17039,55 @@
"redux-first-history": "5.1.1"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/react-redux": {
"name": "@flecks/react-redux",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/react": "^4.0.7",
"@flecks/redux": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/react": "^4.0.8",
"@flecks/redux": "^4.0.8",
"react-redux": "^7.2.2"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/redis": {
"name": "@flecks/redis",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"@socket.io/redis-adapter": "7.1.0",
"connect-redis": "^5.0.0",
"express-session": "^1.17.1",
"redis": "4.0.3"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/redux": {
"name": "@flecks/redux",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"@reduxjs/toolkit": "^1.5.0",
"debug": "^4.3.3",
"lodash.throttle": "^4.1.1",
"reduce-reducers": "^1.0.4"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/redux/node_modules/debug": {
@ -17094,51 +17108,51 @@
},
"packages/repl": {
"name": "@flecks/repl",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"command-exists": "^1.2.9",
"debug": "4.3.1"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/server": {
"name": "@flecks/server",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1"
"@flecks/core": "^4.2.0"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/session": {
"name": "@flecks/session",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/core": "^4.2.0",
"express": "^4.18.2",
"express-session": "^1.17.3"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/socket": {
"name": "@flecks/socket",
"version": "4.0.7",
"version": "4.0.8",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.1.1",
"@flecks/react": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/react": "^4.0.8",
"msgpack-lite": "^0.1.26",
"proxy-addr": "^2.0.6",
"schemapack": "^1.4.2",
@ -17146,19 +17160,19 @@
"socket.io-client": "^4.1.2"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7"
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0"
}
},
"packages/web": {
"name": "@flecks/web",
"version": "4.0.7",
"version": "4.1.0",
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.1.1",
"@flecks/server": "^4.0.7",
"@flecks/core": "^4.2.0",
"@flecks/server": "^4.1.0",
"@webpack-cli/serve": "^2.0.5",
"add-asset-html-webpack-plugin": "^6.0.0",
"assert": "^2.1.0",
@ -17191,8 +17205,8 @@
"webpack-dev-server": "^4.15.1"
},
"devDependencies": {
"@flecks/build": "^4.0.7",
"@flecks/fleck": "^4.0.7",
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0",
"puppeteer": "^22.0.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@flecks/monorepo",
"version": "3.0.0",
"version": "4.0.0",
"private": true,
"repository": {
"type": "git",

119
packages/headless/.gitignore vendored Normal file
View File

@ -0,0 +1,119 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# copy-webpack-plugin charity
.git

View File

@ -0,0 +1,19 @@
{
"name": "@flecks/headless",
"version": "4.0.0",
"scripts": {
"build": "flecks build",
"clean": "flecks clean",
"lint": "flecks lint",
"test": "flecks test"
},
"files": [],
"dependencies": {
"@flecks/core": "^4.0.0"
},
"devDependencies": {
"@flecks/build": "^4.0.0",
"@flecks/fleck": "^4.0.0",
"puppeteer": "^22.0.0"
}
}

View File

@ -1,6 +1,22 @@
import puppeteer from 'puppeteer';
export async function connectBrowser(url, options = {}) {
export async function createBrowser(options = {}) {
let previousTimeout;
const start = Date.now();
if (options.task) {
previousTimeout = options.task.timeout();
options.task.timeout(0);
}
const browser = await puppeteer.launch({
// For CI.
args: ['--no-sandbox'],
});
const page = await browser.newPage();
options.task?.timeout(previousTimeout + (Date.now() - start));
return {browser, page};
}
export async function connectPage(page, url, options = {}) {
let previousTimeout;
const start = Date.now();
if (options.task) {
@ -8,11 +24,6 @@ export async function connectBrowser(url, options = {}) {
options.task.timeout(0);
}
const {timeout = 30000} = options;
const browser = await puppeteer.launch({
// For CI.
args: ['--no-sandbox'],
});
const page = await browser.newPage();
let response;
const handle = setTimeout(() => {
throw new Error(`timed out trying to connect browser to '${url}'!`);
@ -34,5 +45,5 @@ export async function connectBrowser(url, options = {}) {
/* eslint-enable no-await-in-loop */
clearTimeout(handle);
options.task?.timeout(previousTimeout + (Date.now() - start));
return {browser, page, response};
return response;
}

View File

@ -1,11 +1,12 @@
import {startServer} from '@flecks/server/test/helpers/start-server';
import {connectBrowser} from './connect-browser';
import {createBrowser, connectPage} from './connect';
export function withWeb(task, options) {
return async function withWeb() {
const server = await startServer({...options, task: this});
const socket = await server.waitForSocket({...options, task: this});
const optionsWithTask = {...options, task: this};
const server = await startServer(optionsWithTask);
const socket = await server.waitForSocket(optionsWithTask);
if (options.beforeConnect) {
await options.beforeConnect({server, socket});
}
@ -14,20 +15,15 @@ export function withWeb(task, options) {
this.timeout(0);
const {payload: config} = await socket.send({type: 'config.get', payload: '@flecks/web'});
this.timeout(previousTimeout + (Date.now() - start));
const {browser, page, response} = await connectBrowser(
// @todo schema
`http://${config.public}`,
{
...options,
task: this,
},
);
const {browser, page} = await createBrowser(optionsWithTask);
const response = await connectPage(page, `http://${config.public}`, optionsWithTask);
return task({
browser,
page,
response,
server,
socket,
task: this,
});
};
}

View File

@ -21,7 +21,7 @@ export function withServer(task, options) {
};
let taskError;
try {
await task({server, socket});
await task({server, socket, task: this});
}
catch (error) {
taskError = error;

View File

@ -65,6 +65,6 @@
"devDependencies": {
"@flecks/build": "^4.1.0",
"@flecks/fleck": "^4.1.0",
"puppeteer": "^22.0.0"
"@flecks/headless": "^4.0.0"
}
}

View File

@ -1,6 +1,6 @@
import {expect} from 'chai';
import {withWeb} from './helpers/with-web';
import {withWeb} from '@flecks/headless/test/helpers/with-web';
let report;
@ -11,13 +11,15 @@ const options = {
};
it('brings a client up', withWeb(
async function test({
async ({
browser,
page,
response,
}) {
}) => {
expect(response)
.to.not.be.null;
expect(response.ok())
.to.be.true;
const {
payload: {
config,