refactor: testing and file writing within

This commit is contained in:
cha0s 2024-02-10 16:41:04 -06:00
parent fd55670ce1
commit a340798676
22 changed files with 95 additions and 50 deletions

22
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch: {}
jobs:
lint:
uses: ./.github/workflows/node.yml
with:
run: npm run lint
test:
uses: ./.github/workflows/node.yml
with:
run: npm run -- test -p 360000
build:
uses: ./.github/workflows/node.yml
with:
run: npm run build

View File

@ -7,18 +7,6 @@ on:
jobs: jobs:
e2e: e2e:
runs-on: ubuntu-latest uses: ./.github/workflows/node.yml
strategy: with:
matrix: run: npm run -- test -t 360000 -p e2e
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm config set registry ${{ vars.NPM_CI_REGISTRY }}
if: ${{ vars.NPM_CI_REGISTRY }}
- run: npm ci
- run: npm run -- test -t 120000 -p e2e

View File

@ -1,14 +1,14 @@
name: CI name: Continuous Integration
on: on:
push: workflow_call:
branches: [master] inputs:
pull_request: run:
branches: [master] required: true
workflow_dispatch: {} type: string
jobs: jobs:
verify: node:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
@ -20,7 +20,8 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
cache: 'npm' cache: 'npm'
- run: npm ${{ vars.NPM_CI_FLAGS }} ci - run: npm config set registry ${{ vars.NPM_CI_REGISTRY }}
- run: npm run lint if: ${{ vars.NPM_CI_REGISTRY }}
- run: npm run test - run: |
- run: npm run build npm ci
${{ inputs.run }}

View File

@ -2,13 +2,14 @@ const {Buffer} = require('buffer');
const {exec} = require('child_process'); const {exec} = require('child_process');
const {createHash} = require('crypto'); const {createHash} = require('crypto');
const {createReadStream} = require('fs'); const {createReadStream} = require('fs');
const {cp, mkdir, writeFile} = require('fs/promises'); const {cp, mkdir} = require('fs/promises');
const {join} = require('path'); const {join} = require('path');
const { const {
processCode, processCode,
run, run,
spawnWith, spawnWith,
writeFile,
} = require('@flecks/core/src/server'); } = require('@flecks/core/src/server');
const Arborist = require('@npmcli/arborist'); const Arborist = require('@npmcli/arborist');
const {glob} = require('glob'); const {glob} = require('glob');

View File

@ -8,14 +8,14 @@
}, },
"scripts": { "scripts": {
"build": "node build/tasks npm run build", "build": "node build/tasks npm run build",
"ci": "act -j verify",
"dox:bump": "npm run dox:gh-pages && cd dox && git add . && git commit -m $(git -C .. rev-parse HEAD) && git push origin gh-pages", "dox:bump": "npm run dox:gh-pages && cd dox && git add . && git commit -m $(git -C .. rev-parse HEAD) && git push origin gh-pages",
"dox:gh-pages": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus build --out-dir ../dox-tmp && cd .. && rm -rf dox/* && mv dox-tmp/* dox && rmdir dox-tmp", "dox:gh-pages": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus build --out-dir ../dox-tmp && cd .. && rm -rf dox/* && mv dox-tmp/* dox && rmdir dox-tmp",
"dox:serve": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus build --no-minify --out-dir ../dox-tmp && node_modules/.bin/docusaurus serve --dir ../dox-tmp", "dox:serve": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus build --no-minify --out-dir ../dox-tmp && node_modules/.bin/docusaurus serve --dir ../dox-tmp",
"dox": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus", "dox": "flecks dox docusaurus && cd website && DOCUSAURUS_GENERATED_FILES_DIR_NAME=node_modules/.cache/docusaurus node_modules/.bin/docusaurus",
"lint": "node build/tasks npm run lint", "lint": "node build/tasks npm run lint",
"publish": "node build/publish --provenance", "publish": "node build/publish --provenance",
"test": "node build/tasks npm run -- test" "test": "node build/tasks npm run -- test",
"verify": "act workflow_dispatch"
}, },
"workspaces": [ "workspaces": [
"packages/*" "packages/*"

View File

@ -2,7 +2,6 @@ const {
access, access,
constants: {R_OK, W_OK}, constants: {R_OK, W_OK},
readFile, readFile,
writeFile,
} = require('fs/promises'); } = require('fs/promises');
const { const {
dirname, dirname,
@ -27,6 +26,7 @@ const {
loadYml, loadYml,
lockFile, lockFile,
spawnWith, spawnWith,
writeFile,
} = require('@flecks/core/src/server'); } = require('@flecks/core/src/server');
const chokidar = require('chokidar'); const chokidar = require('chokidar');
const {glob} = require('glob'); const {glob} = require('glob');

View File

@ -1,4 +1,3 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {createWorkspace} from '@flecks/core/build/testing'; import {createWorkspace} from '@flecks/core/build/testing';
@ -7,6 +6,7 @@ import {
pipesink, pipesink,
processCode, processCode,
spawnWith, spawnWith,
writeFile,
} from '@flecks/core/server'; } from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';

View File

@ -1,10 +1,11 @@
import {mkdir, writeFile} from 'fs/promises'; import {mkdir} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {expect} from 'chai'; import {expect} from 'chai';
import explicate from '@flecks/build/build/explicate'; import explicate from '@flecks/build/build/explicate';
import Resolver from '@flecks/build/build/resolver'; import Resolver from '@flecks/build/build/resolver';
import {writeFile} from '@flecks/core/server';
const { const {
FLECKS_CORE_ROOT = process.cwd(), FLECKS_CORE_ROOT = process.cwd(),

View File

@ -1,10 +1,9 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {createWorkspace} from '@flecks/core/build/testing';
import {expect} from 'chai';
import Resolver from '@flecks/build/build/resolver'; import Resolver from '@flecks/build/build/resolver';
import {createWorkspace} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai';
it('uses NODE_PATH when resolving', async () => { it('uses NODE_PATH when resolving', async () => {
const workspace = await createWorkspace(); const workspace = await createWorkspace();

View File

@ -1,7 +1,7 @@
import addPathsToYml from '@flecks/core/build/add-paths-to-yml'; import addPathsToYml from '@flecks/core/build/add-paths-to-yml';
import {loadYml} from '@flecks/core/server'; import {loadYml, writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {readFile, writeFile} from 'fs/promises'; import {readFile} from 'fs/promises';
it('can add paths to YML', async () => { it('can add paths to YML', async () => {
await writeFile( await writeFile(

View File

@ -1,8 +1,10 @@
const {readFile, writeFile} = require('fs/promises'); const {readFile} = require('fs/promises');
const {join} = require('path'); const {join} = require('path');
const {dump: dumpYml, load: loadYml} = require('js-yaml'); const {dump: dumpYml, load: loadYml} = require('js-yaml');
const {writeFile} = require('../src/server/fs');
const { const {
FLECKS_CORE_ROOT = process.cwd(), FLECKS_CORE_ROOT = process.cwd(),
} = process.env; } = process.env;

View File

@ -0,0 +1,17 @@
const {open, writeFile} = require('fs/promises');
exports.writeFile = async (
path,
content,
paramaterizedOptions,
) => {
const options = {
flags: 'w',
mode: 0o666,
...paramaterizedOptions,
};
const filehandle = await open(path, options.flags, options.mode);
await writeFile(filehandle, content, options);
await filehandle.sync();
await filehandle.close();
};

View File

@ -7,6 +7,7 @@ module.exports = {
glob: require('glob').glob, glob: require('glob').glob,
loadYml, loadYml,
...require('../../build/stream'), ...require('../../build/stream'),
...require('./fs'),
...require('./package-manager'), ...require('./package-manager'),
...require('./process'), ...require('./process'),
}; };

View File

@ -0,0 +1,17 @@
/* eslint-disable camelcase */
import {access} from 'fs/promises';
import {join} from 'path';
import {createWorkspace} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
it('writes files', async () => {
const workspace = await createWorkspace();
/* eslint-disable no-await-in-loop */
for (let i = 0; i < 10; ++i) {
const path = join(workspace, `${i}`);
await writeFile(path, '');
await access(path);
}
});

View File

@ -16,9 +16,6 @@ before(heavySetup(async () => {
artifact = true; artifact = true;
} }
catch (error) { catch (error) {
// intermittent failure...
// eslint-disable-next-line no-console
console.error(error);
artifact = false; artifact = false;
} }
})); }));

View File

@ -16,8 +16,6 @@ before(heavySetup(async () => {
artifact = true; artifact = true;
} }
catch (error) { catch (error) {
// intermittent failure...
console.error(error); // eslint-disable-line no-console
artifact = false; artifact = false;
} }
})); }));

View File

@ -1,7 +1,7 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {build, createApplication} from './build/build'; import {build, createApplication} from './build/build';

View File

@ -1,7 +1,7 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {buildChild, createApplication} from './build/build'; import {buildChild, createApplication} from './build/build';

View File

@ -1,7 +1,7 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {build, createApplication} from './build/build'; import {build, createApplication} from './build/build';

View File

@ -1,7 +1,8 @@
import {mkdir, writeFile} from 'fs/promises'; import {mkdir} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {build, createApplication, serverActions} from './build/build'; import {build, createApplication, serverActions} from './build/build';

View File

@ -1,7 +1,7 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {build, createApplication, serverActions} from './build/build'; import {build, createApplication, serverActions} from './build/build';

View File

@ -1,7 +1,7 @@
import {writeFile} from 'fs/promises';
import {join} from 'path'; import {join} from 'path';
import {heavySetup} from '@flecks/core/build/testing'; import {heavySetup} from '@flecks/core/build/testing';
import {writeFile} from '@flecks/core/server';
import {expect} from 'chai'; import {expect} from 'chai';
import {buildChild, createApplication} from './build/build'; import {buildChild, createApplication} from './build/build';