Skip to content

Latest commit

 

History

History
483 lines (460 loc) · 13.2 KB

test.js.md

File metadata and controls

483 lines (460 loc) · 13.2 KB

Snapshot report for test.js

The actual snapshot is saved in test.js.snap.

Generated by AVA.

snapshot for a bunch of commands

seam-plop ava-config

`// ava.config.js␊

module.exports = {␊
  files: ["src/tests/**/*.test.ts"],␊
  extensions: ["ts"],␊
  require: ["esbuild-register"],␊
  ignoredByWatcher: [".next", ".nsm"],␊
}`

seam-plop gitignore

`// .gitignore␊

node_modules␊
dist␊
.vercel␊
.next␊
yarn-error.log␊
.nsm␊
.vscode␊
.env*␊
!.env.example␊
.DS_Store␊
.yalc␊
yalc.lock`

seam-plop prettierrc yes

`// .prettierrc␊

{ "semi": false }␊



// package.json␊

{␊
  "name": "some-package",␊
  "devDependencies": {␊
    "prettier": "^2.7.1"␊
  }␊
}`

seam-plop node-pg-migrate no

`// package.json␊

{␊
  "name": "some-package",␊
  "scripts": {␊
    "db:create-migration": "node-pg-migrate --migration-file-language ts -m src/db/migrations create",␊
    "db:migrate": "esr src/scripts/migrate-db.ts",␊
    "db:reset": "esr src/scripts/reset-db.ts"␊
  },␊
  "devDependencies": {␊
    "chalk": "^5.0.1",␊
    "debug": "^4.3.4",␊
    "node-pg-migrate": "^6.2.2",␊
    "pg-connection-from-env": "^1.0.3"␊
  },␊
  "dependencies": {␊
    "pg": "^8.8.0",␊
    "zapatos": "^6.0.1"␊
  }␊
}␊



// src/scripts/migrate-db.ts␊

import migrateDb from "lib/migrate-db"␊

migrateDb()␊


// src/scripts/reset-db.ts␊

import resetDb from "lib/reset-db"␊

resetDb()␊


// src/lib/db/migrate-db.ts␊

import nodePgMigrate from "node-pg-migrate"␊
import getDB from "db/get-db"␊
import * as zg from "zapatos/generate"␊
import { Client } from "pg"␊
import Debug from "debug"␊

const debug = Debug("MY_PROJECT_NAME")␊

export const migrate = async ({␊
  database_url,␊
  db,␊
  update_typings = false,␊
  silent = false,␊
}: {␊
  database_url?: string␊
  db?: any␊
  update_typings?: boolean␊
  silent?: boolean␊
} = {}) => {␊
  let client␊

  if (!database_url) {␊
    const conn = db?.connection || getDB.getConnectionInfo()␊
    client = new Client(conn)␊
    const { host, password, port, database, user, ssl } = conn␊
    database_url = \`postgresql://${user}:${password}@${host}:${port}/${database}${
      ssl ? "?sslmode=no-verify" : ""
    }\`␊
  }␊

  client = new Client({␊
    connectionString: database_url,␊
  })␊

  await client.connect()␊

  let logger␊

  if (silent) {␊
    logger = {␊
      ...console,␊
      info: () => null,␊
      log: () => null,␊
    }␊
  } else {␊
    logger =␊
      debug.enabled || process.env.NODE_ENV !== "test"␊
        ? console␊
        : {␊
            ...console,␊
            info: () => null,␊
            log: () => null,␊
          }␊
  }␊

  await Promise.all([␊
    nodePgMigrate({␊
      dbClient: client,␊
      direction: "up",␊
      schema: "migrations",␊
      createSchema: true,␊
      migrationsTable: "pgmigrations",␊
      verbose: false,␊
      dir: "./db/migrations",␊
      logger,␊
    } as any),␊
    // TODO put graphile worker migration here␊
  ])␊

  if (update_typings) {␊
    const schemas = [␊
      // TODO insert schemas to type␊
    ]␊
    await zg.generate({␊
      db: {␊
        connectionString: database_url,␊
      },␊
      schemas: Object.fromEntries(␊
        schemas.map((s) => [␊
          s,␊
          {␊
            include: "*",␊
            exclude: [],␊
          },␊
        ])␊
      ),␊
      outDir: "./src/db",␊
    })␊
  }␊

  await client.end()␊
}␊

export default migrate␊


// src/lib/db/reset-db.ts␊

import process from "node:process"␊
import chalk from "chalk"␊
import { Client } from "pg"␊
import { migrate } from "./migrate-db"␊
import { getConnectionStringFromEnv } from "pg-connection-from-env"␊

export const reset = async () => {␊
  const postgres_db = new Client({␊
    connectionString: getConnectionStringFromEnv({ database: "postgres" }),␊
  })␊
  const seam_db = new Client({␊
    connectionString: getConnectionStringFromEnv(),␊
  })␊

  const database_name = seam_db.database!␊

  console.log(chalk.green(\`Dropping database "${database_name}"...\`))␊

  await postgres_db.connect()␊
  try {␊
    await postgres_db.query(\`DROP DATABASE ${database_name} WITH (FORCE);\`)␊
  } catch {}␊

  console.log(chalk.green(\`Creating database "${database_name}"...\`))␊
  await postgres_db.query(\`CREATE DATABASE ${database_name};\`)␊

  console.log(chalk.green("Running migrations..."))␊
  await migrate({ database_url: DATABASE_URL, update_typings: true })␊

  console.log(chalk.green("Finished migrating"))␊

  await Promise.all([seam_db.end(), postgres_db.end()])␊
}␊

void reset().catch((error) => {␊
  console.error(error)␊
  // eslint-disable-next-line unicorn/no-process-exit␊
  process.exit(1)␊
})`

seam-plop github-ci-test no

`// .github/workflows/npm-test.yml␊

name: NPM Test␊
on: [push]␊
jobs:␊
  npm_test:␊
    if: "!contains(github.event.head_commit.message, 'skip ci')"␊
    name: Run NPM Test␊
    runs-on: ubuntu-20.04␊
    steps:␊
      - name: Checkout␊
        uses: actions/checkout@v1␊
      - name: Setup Node.js␊
        uses: actions/setup-node@v2␊
        with:␊
          node-version: 16␊
          cache: "yarn"␊
      - name: Run NPM Install␊
        run: yarn install --frozen-lockfile␊
      - name: Run NPM Test␊
        run: yarn test`

seam-plop github-ci-test yes

`// .github/workflows/npm-test.yml␊

name: NPM Test␊
on: [push]␊
jobs:␊
  npm_test:␊
    if: "!contains(github.event.head_commit.message, 'skip ci')"␊
    name: Run NPM Test␊
    runs-on: ubuntu-20.04␊
    services:␊
      postgres:␊
        image: postgres␊
        env:␊
          POSTGRES_HOST_AUTH_METHOD: trust␊
        options: >-␊
          --health-cmd pg_isready␊
          --health-interval 10s␊
          --health-timeout 5s␊
          --health-retries 5␊
        ports:␊
          - 5432:5432␊
    steps:␊
      - name: Checkout␊
        uses: actions/checkout@v1␊
      - name: Setup Node.js␊
        uses: actions/setup-node@v2␊
        with:␊
          node-version: 16␊
          cache: "yarn"␊
      - name: Run NPM Install␊
        run: yarn install --frozen-lockfile␊
      - name: Run NPM Test␊
        run: yarn test`

seam-plop github-ci-vercel-deploy yes

`// .github/vercel-deploy.yml␊

name: Deploy to Vercel␊
on:␊
  push:␊
    branches: ["main"]␊
jobs:␊
  migrate_and_deploy:␊
    if: "!contains(github.event.head_commit.message, 'skip ci')"␊
    name: Migrate and Deploy␊
    runs-on: ubuntu-20.04␊
    timeout-minutes: 10␊
    steps:␊
      - name: Checkout␊
        uses: actions/checkout@v1␊
      - name: Setup Node.js␊
        uses: actions/setup-node@v2␊
        with:␊
          node-version: 16␊
          registry-url: "https://npm.pkg.github.com"␊
          cache: "yarn"␊
      - name: Migrate Database␊
        run: npm run db:migrate␊
        env:␊
          DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}␊
      - name: Tell Vercel to deploy␊
        uses: amondnet/vercel-action@v25.1.0␊
        with:␊
          vercel-token: ${{ secrets.VERCEL_TOKEN }} # Org Secret␊
          vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} # Repo Secret␊
          vercel-org-id: ${{ secrets.VERCEL_TEAM_ID }} # Org Secret␊
          scope: ${{ secrets.VERCEL_TEAM_ID }} # Org Secret␊
          vercel-args: --prod`

seam-plop github-ci-release no no

`// package.json␊

{␊
  "name": "some-package",␊
  "devDependencies": {␊
    "@semantic-release/commit-analyzer": "^9.0.2",␊
    "@semantic-release/git": "^10.0.1",␊
    "@semantic-release/npm": "^9.0.1",␊
    "@semantic-release/release-notes-generator": "^10.0.3"␊
  }␊
}␊



// release.config.js␊

module.exports = {␊
  branches: ["main"],␊
  plugins: [␊
    "@semantic-release/commit-analyzer",␊
    "@semantic-release/release-notes-generator",␊
    ["@semantic-release/npm", { npmPublish: true }],␊
    [␊
      "@semantic-release/git",␊
      {␊
        assets: ["package.json"],␊
        message:␊
          "chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}",␊
      },␊
    ],␊
  ],␊
}␊



// .github/workflows/npm-semantic-release.yml␊

name: NPM Semantic Release␊
on:␊
  push:␊
    branches:␊
      - main␊
jobs:␊
  publish:␊
    if: "!contains(github.event.head_commit.message, 'skip ci')"␊
    name: Release␊
    runs-on: ubuntu-20.04␊
    steps:␊
      - name: Checkout␊
        uses: actions/checkout@v1␊
      - name: Setup Node.js␊
        uses: actions/setup-node@v2␊
        with:␊
          node-version: "16.x"␊
          cache: "yarn"␊
      - name: Install dependencies␊
        env:␊
          NODE_AUTH_TOKEN: ${{ secrets.SEAMAPI_NPM_TOKEN }}␊
        run: yarn install␊
      - name: Release␊
        env:␊
          NODE_AUTH_TOKEN: ${{ secrets.SEAMAPI_NPM_TOKEN }}␊
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}␊
        run: npx semantic-release`

seam-plop github-ci-release yes no

`// package.json␊

{␊
  "name": "some-package",␊
  "devDependencies": {␊
    "@semantic-release/commit-analyzer": "^9.0.2",␊
    "@semantic-release/git": "^10.0.1",␊
    "@semantic-release/npm": "^9.0.1",␊
    "@semantic-release/release-notes-generator": "^10.0.3"␊
  }␊
}␊



// release.config.js␊

module.exports = {␊
  branches: ["main"],␊
  plugins: [␊
    "@semantic-release/commit-analyzer",␊
    "@semantic-release/release-notes-generator",␊
    ["@semantic-release/npm", { npmPublish: true }],␊
    [␊
      "@semantic-release/git",␊
      {␊
        assets: ["package.json"],␊
        message:␊
          "chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}",␊
      },␊
    ],␊
  ],␊
}␊



// .github/workflows/npm-semantic-release.yml␊

name: NPM Semantic Release␊
on:␊
  push:␊
    branches:␊
      - main␊
jobs:␊
  publish:␊
    if: "!contains(github.event.head_commit.message, 'skip ci')"␊
    name: Release␊
    runs-on: ubuntu-20.04␊
    steps:␊
      - name: Checkout␊
        uses: actions/checkout@v1␊
      - name: Setup Node.js␊
        uses: actions/setup-node@v2␊
        with:␊
          node-version: "16.x"␊
          cache: "yarn"␊
          registry-url: "https://npm.pkg.github.com"␊
      - name: Install dependencies␊
        env:␊
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}␊
        run: yarn install`

seam-plop tsconfig

`// tsconfig.json␊

{␊
  "compilerOptions": {␊
    "target": "esnext",␊
    "lib": ["dom", "dom.iterable", "esnext"],␊
    "allowJs": true,␊
    "skipLibCheck": true,␊
    "strict": true,␊
    "forceConsistentCasingInFileNames": true,␊
    "noEmit": true,␊
    "incremental": false,␊
    "esModuleInterop": true,␊
    "module": "esnext",␊
    "moduleResolution": "node",␊
    "resolveJsonModule": true,␊
    "isolatedModules": true,␊
    "jsx": "preserve",␊
    "baseUrl": "./src"␊
  },␊
  "include": ["next-env.d.ts", "**/*.ts"],␊
  "exclude": ["node_modules"]␊
}`