Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Dec 7, 2023
1 parent 842e183 commit de05feb
Show file tree
Hide file tree
Showing 154 changed files with 1,499 additions and 2,395 deletions.
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

20 changes: 15 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// jest.config.js
const base = require('./jest.config.base.js')

module.exports = {
...base,
projects: ['<rootDir>/packages/*/jest.config.js'],
projects: [
// '<rootDir>/packages/*/jest.config.js'


'<rootDir>/packages/api/jest.config.js',
'<rootDir>/packages/common/jest.config.js',
'<rootDir>/packages/common-web/jest.config.js',
'<rootDir>/packages/crypto/jest.config.js',
'<rootDir>/packages/identity/jest.config.js',
'<rootDir>/packages/lexicon/jest.config.js',
'<rootDir>/packages/repo/jest.config.js',
'<rootDir>/packages/syntax/jest.config.js',
// '<rootDir>/packages/xrpc/jest.config.js',
'<rootDir>/packages/xrpc-server/jest.config.js',
],
}
27 changes: 8 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,35 @@
"lint": "eslint . --ext .ts,.tsx",
"verify": "prettier --check . && pnpm lint",
"format": "prettier --write .",
"build": "pnpm -r --stream build",
"update-main-to-dist": "pnpm -r --stream update-main-to-dist",
"test": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test",
"test:withFlags": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test --",
"build": "npm-run-all build:tsc build:packages",
"build:tsc": "NODE_ENV=production tsc --build --verbose --force",
"build:packages": "NODE_ENV=production pnpm run --recursive build",
"test": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh jest",
"test:withFlags": "LOG_ENABLED=false NODE_ENV=development ./packages/dev-infra/with-test-redis-and-db.sh jest --",
"changeset": "changeset",
"release": "pnpm build && changeset publish",
"version-packages": "changeset version && git add ."
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@npmcli/package-json": "^3.0.0",
"@swc/core": "^1.3.42",
"@swc/jest": "^0.2.24",
"@types/jest": "^28.1.4",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"babel-eslint": "^10.1.0",
"dotenv": "^16.0.3",
"esbuild": "^0.14.48",
"esbuild-node-externals": "^1.5.0",
"esbuild-plugin-handlebars": "^1.0.2",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"handlebars-jest": "^1.0.0",
"jest": "^28.1.2",
"jest": "^29.7.0",
"node-gyp": "^9.3.1",
"npm-run-all": "^4.1.5",
"pino-pretty": "^9.1.0",
"prettier": "^2.7.1",
"prettier-config-standard": "^5.0.0",
"ts-node": "^10.8.2",
"typescript": "^4.8.4"
},
"workspaces": {
"packages": [
"packages/*"
]
"typescript": "^5.3.2"
}
}
3 changes: 0 additions & 3 deletions packages/api/babel.config.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/api/build.js

This file was deleted.

7 changes: 4 additions & 3 deletions packages/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const base = require('../../jest.config.base.js')

/** @type {import('jest').Config} */
module.exports = {
...base,
displayName: 'API',
transform: { '^.+\\.(t|j)s?$': '@swc/jest' },
transformIgnorePatterns: [`<rootDir>/node_modules/(?!get-port)`],
setupFiles: ['<rootDir>/jest.setup.ts'],
}
19 changes: 19 additions & 0 deletions packages/api/jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
declare namespace jest {
interface Matchers<R, T = {}> {
toBeModerationResult(
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause?: boolean,
): R
}

interface Expect {
toBeModerationResult(
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause?: boolean,
): void
}
}
79 changes: 79 additions & 0 deletions packages/api/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { ModerationBehaviorResult } from './definitions/moderation-behaviors'
import { ModerationUI } from './src'

expect.extend({
toBeModerationResult(
actual: ModerationUI,
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause = false,
) {
const fail = (msg: string) => ({
pass: false,
message: () => `${msg}. Full result: ${stringifiedResult}`,
})
let cause = actual.cause?.type as string
if (actual.cause?.type === 'label') {
cause = `label:${actual.cause.labelDef.id}`
} else if (actual.cause?.type === 'muted') {
if (actual.cause.source.type === 'list') {
cause = 'muted-by-list'
}
} else if (actual.cause?.type === 'blocking') {
if (actual.cause.source.type === 'list') {
cause = 'blocking-by-list'
}
}
if (!expected) {
if (!ignoreCause && actual.cause) {
return fail(`${context} expected to be a no-op, got ${cause}`)
}
if (actual.alert) {
return fail(`${context} expected to be a no-op, got alert=true`)
}
if (actual.blur) {
return fail(`${context} expected to be a no-op, got blur=true`)
}
if (actual.filter) {
return fail(`${context} expected to be a no-op, got filter=true`)
}
if (actual.noOverride) {
return fail(`${context} expected to be a no-op, got noOverride=true`)
}
} else {
if (!ignoreCause && cause !== expected.cause) {
return fail(`${context} expected to be ${expected.cause}, got ${cause}`)
}
if (!!actual.alert !== !!expected.alert) {
return fail(
`${context} expected to be alert=${expected.alert || false}, got ${
actual.alert || false
}`,
)
}
if (!!actual.blur !== !!expected.blur) {
return fail(
`${context} expected to be blur=${expected.blur || false}, got ${
actual.blur || false
}`,
)
}
if (!!actual.filter !== !!expected.filter) {
return fail(
`${context} expected to be filter=${expected.filter || false}, got ${
actual.filter || false
}`,
)
}
if (!!actual.noOverride !== !!expected.noOverride) {
return fail(
`${context} expected to be noOverride=${
expected.noOverride || false
}, got ${actual.noOverride || false}`,
)
}
}
return { pass: true, message: () => '' }
},
})
13 changes: 4 additions & 9 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
"url": "https://github.com/bluesky-social/atproto",
"directory": "packages/api"
},
"main": "src/index.ts",
"publishConfig": {
"main": "dist/index.js",
"types": "dist/index.d.ts"
},
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
"docgen": "node ./scripts/generate-docs.mjs",
"build": "node ./build.js",
"postbuild": "tsc --build tsconfig.build.json",
"update-main-to-dist": "node ../../update-main-to-dist.js packages/api",
"test": "jest",
"bench": "jest --config jest.bench.config.js",
"bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js"
Expand All @@ -36,11 +31,11 @@
"@atproto/xrpc": "workspace:^",
"multiformats": "^9.9.0",
"tlds": "^1.234.0",
"tslib": "^2.6.2",
"typed-emitter": "^2.1.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@atproto/lex-cli": "workspace:^",
"@atproto/dev-env": "workspace:^",
"common-tags": "^1.8.2"
}
Expand Down
6 changes: 4 additions & 2 deletions packages/api/tests/profile-moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ describe('Post moderation behaviors', () => {
suiteRunner.moderationOpts(scenario),
)
expect(res.account).toBeModerationResult(
// @ts-expect-error TODO FIXME
scenario.behaviors.account,
'account',
JSON.stringify(res, null, 2),
)
expect(res.profile).toBeModerationResult(
)
expect(res.profile).toBeModerationResult(
// @ts-expect-error TODO FIXME
scenario.behaviors.profile,
'profile content',
JSON.stringify(res, null, 2),
Expand Down
82 changes: 2 additions & 80 deletions packages/api/tests/util/moderation-behavior.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,10 @@
import { ModerationUI, ModerationOpts, ComAtprotoLabelDefs } from '../../src'
import type {
ModerationBehaviors,
ModerationBehaviorScenario,
ModerationBehaviorResult,
ModerationBehaviors
} from '../../definitions/moderation-behaviors'
import { ComAtprotoLabelDefs, ModerationOpts } from '../../src'
import { mock as m } from './index'

expect.extend({
toBeModerationResult(
actual: ModerationUI,
expected: ModerationBehaviorResult | undefined,
context: string,
stringifiedResult: string,
ignoreCause = false,
) {
const fail = (msg: string) => ({
pass: false,
message: () => `${msg}. Full result: ${stringifiedResult}`,
})
let cause = actual.cause?.type as string
if (actual.cause?.type === 'label') {
cause = `label:${actual.cause.labelDef.id}`
} else if (actual.cause?.type === 'muted') {
if (actual.cause.source.type === 'list') {
cause = 'muted-by-list'
}
} else if (actual.cause?.type === 'blocking') {
if (actual.cause.source.type === 'list') {
cause = 'blocking-by-list'
}
}
if (!expected) {
if (!ignoreCause && actual.cause) {
return fail(`${context} expected to be a no-op, got ${cause}`)
}
if (actual.alert) {
return fail(`${context} expected to be a no-op, got alert=true`)
}
if (actual.blur) {
return fail(`${context} expected to be a no-op, got blur=true`)
}
if (actual.filter) {
return fail(`${context} expected to be a no-op, got filter=true`)
}
if (actual.noOverride) {
return fail(`${context} expected to be a no-op, got noOverride=true`)
}
} else {
if (!ignoreCause && cause !== expected.cause) {
return fail(`${context} expected to be ${expected.cause}, got ${cause}`)
}
if (!!actual.alert !== !!expected.alert) {
return fail(
`${context} expected to be alert=${expected.alert || false}, got ${
actual.alert || false
}`,
)
}
if (!!actual.blur !== !!expected.blur) {
return fail(
`${context} expected to be blur=${expected.blur || false}, got ${
actual.blur || false
}`,
)
}
if (!!actual.filter !== !!expected.filter) {
return fail(
`${context} expected to be filter=${expected.filter || false}, got ${
actual.filter || false
}`,
)
}
if (!!actual.noOverride !== !!expected.noOverride) {
return fail(
`${context} expected to be noOverride=${
expected.noOverride || false
}, got ${actual.noOverride || false}`,
)
}
}
return { pass: true, message: () => '' }
},
})

export class ModerationBehaviorSuiteRunner {
constructor(public suite: ModerationBehaviors) {}

Expand Down
8 changes: 6 additions & 2 deletions packages/api/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
"extends": "../../tsconfig/base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
},
"include": ["./src"]
}
13 changes: 4 additions & 9 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist", // Your outDir,
"emitDeclarationOnly": true
},
"include": ["./src"],
"include": [],
"references": [
{ "path": "../xrpc/tsconfig.build.json" },
{ "path": "../lex-cli/tsconfig.build.json" }
{ "path": "./tsconfig.build.json" },
{ "path": "./tsconfig.scripts.json" },
{ "path": "./tsconfig.test.json" }
]
}
8 changes: 8 additions & 0 deletions packages/api/tsconfig.scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig/scripts.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./*.js", "./*.ts"],
"exclude": ["node_modules", "./jest.setup.ts"]
}
Loading

0 comments on commit de05feb

Please sign in to comment.