-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): use kont for tests (#149)
- Loading branch information
1 parent
fa58349
commit 1218c7e
Showing
13 changed files
with
1,916 additions
and
2,111 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GraphQLClient } from 'graphql-request' | ||
import { createDynamicProvider, Nothing } from 'kont' | ||
|
||
export type Needs = Nothing | ||
|
||
export type Contributes = { | ||
graphQLClient: GraphQLClient | ||
} | ||
|
||
export const graphQLClient = () => | ||
createDynamicProvider<Needs, Contributes>((register) => | ||
register.before(() => { | ||
const graphQLClient = new GraphQLClient(`http://localhost:4000/graphql`) | ||
return { | ||
graphQLClient, | ||
} | ||
}) | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as Execa from 'execa' | ||
import { createDynamicProvider } from 'kont' | ||
import { Providers } from 'kont/providers' | ||
import { merge } from 'lodash' | ||
import readPkgUp from 'read-pkg-up' | ||
import { PackageJson, TsConfigJson } from 'type-fest' | ||
import { assertBuildPresent } from '../__helpers__/helpers' | ||
|
||
type Project = { | ||
thisPackageName: string | ||
fixture: { | ||
use(path: string): void | ||
} | ||
packageJson: { | ||
merge(fields: PackageJson): void | ||
create(fields: PackageJson): void | ||
} | ||
tsconfig: { | ||
merge(fields: TsConfigJson): void | ||
create(fields: TsConfigJson): void | ||
} | ||
} | ||
|
||
export type Needs = Providers.Dir.Contributes & Providers.Run.Contributes | ||
|
||
export type Contributes = Project | ||
|
||
export const project = () => | ||
createDynamicProvider<Needs, Contributes>((register) => | ||
register.before((ctx) => { | ||
assertBuildPresent() | ||
Execa.commandSync(`yalc publish --no-scripts`) | ||
|
||
const thisPackageJson = readPkgUp.sync({ cwd: __dirname })?.packageJson | ||
|
||
if (!thisPackageJson) { | ||
throw new Error(`Failed to get own package.json`) | ||
} | ||
|
||
const thisPackageName = thisPackageJson.name | ||
|
||
const api: Project = { | ||
thisPackageName, | ||
fixture: { | ||
use: (path) => { | ||
ctx.fs.copy(path, ctx.fs.cwd(), { | ||
overwrite: true, | ||
}) | ||
}, | ||
}, | ||
packageJson: { | ||
create: (packageJson) => { | ||
const fileName = 'package.json' | ||
ctx.fs.write(fileName, packageJson, { jsonIndent: 2 }) | ||
}, | ||
merge: (fields) => { | ||
const fileName = 'package.json' | ||
const PackageJson = ctx.fs.read(fileName, 'json') | ||
const PackageJsonNew = merge(PackageJson, fields) | ||
ctx.fs.write(fileName, PackageJsonNew, { jsonIndent: 2 }) | ||
}, | ||
}, | ||
tsconfig: { | ||
create: (tsconfig) => { | ||
const fileName = 'tsconfig.json' | ||
ctx.fs.write(fileName, tsconfig, { jsonIndent: 2 }) | ||
}, | ||
merge: (fields) => { | ||
const fileName = 'tsconfig.json' | ||
const tsconfig = ctx.fs.read(fileName, 'json') | ||
const tsconfigNew = merge(tsconfig, fields) | ||
ctx.fs.write(fileName, tsconfigNew, { jsonIndent: 2 }) | ||
}, | ||
}, | ||
} | ||
|
||
api.packageJson.create({ | ||
name: 'some-test-project', | ||
version: '1.0.0', | ||
}) | ||
|
||
api.tsconfig.create({ | ||
compilerOptions: { | ||
strict: true, | ||
target: 'ES2018', | ||
module: 'CommonJS', | ||
moduleResolution: 'node', | ||
rootDir: 'src', | ||
outDir: 'build', | ||
esModuleInterop: true, // for ApolloServer b/c ws dep :( | ||
}, | ||
include: ['src'], | ||
}) | ||
|
||
// d(`starting project setup`) | ||
// Execa.commandSync(`yalc publish --no-scripts`) | ||
// ctx.runOrThrow(`yalc add ${thisPackageName}`) | ||
// ctx.runOrThrow(`npm install --legacy-peer-deps`) | ||
// d(`done project setup`) | ||
|
||
return api | ||
}) | ||
) |
Oops, something went wrong.
1218c7e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: