Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[legacy-framework] Add new integration test harness #2189

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ module.exports = {
},
},
{
files: ["**/__fixtures__/**"],
files: ["test/**", "**/__fixtures__/**"],
rules: {
"import/no-default-export": "off",
"require-await": "off",
},
},
],
Expand Down
40 changes: 37 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
path: ./*
key: ${{ github.sha }}

build_and_test_pkgs:
testBlitzPackages:
name: Blitz Packages Tests
needs: build
runs-on: ubuntu-latest
Expand All @@ -108,7 +108,7 @@ jobs:
env:
CI: true

build_and_test_examples:
testBlitzExamples:
timeout-minutes: 30
name: Blitz Example Apps Tests
strategy:
Expand Down Expand Up @@ -193,6 +193,32 @@ jobs:
- run: node run-tests.js --timings --type unit -g 1/1
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testIntegrationBlitz:
name: Blitz - Test Integration
runs-on: ubuntu-latest
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
HEADLESS: true
strategy:
fail-fast: false
steps:
- run: echo ${{needs.build.outputs.docsChange}}
- uses: actions/cache@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}

# TODO: remove after we fix watchpack watching too much
- run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

- run: xvfb-run node nextjs/run-tests.js -c 3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testIntegration:
name: Nextjs - Test Integration
defaults:
Expand Down Expand Up @@ -259,7 +285,15 @@ jobs:
testsPass:
name: thank you, next
runs-on: ubuntu-latest
needs: [checkPrecompiled, testIntegration, testUnit]
needs:
[
checkPrecompiled,
testIntegration,
testIntegrationBlitz,
testUnit,
testBlitzPackages,
testBlitzExamples,
]
steps:
- run: exit 0

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.log
.DS_Store
.jest-*
lib
packages/cli/lib
node_modules
reports
*.log
Expand Down
20 changes: 20 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,24 @@ module.exports = {
},
],
],
overrides: [
{
test: "./test/**/*",
presets: [
[
"@babel/preset-env",
{
modules: false,
// loose: true,
exclude: [
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-regenerator",
],
},
],
"blitz/babel",
],
plugins: [],
},
],
}
39 changes: 18 additions & 21 deletions examples/auth/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
const withMonorepoBuildTooling = require("@preconstruct/next")
const {sessionMiddleware, simpleRolesIsAuthorized} = require("blitz")
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
})

module.exports = withMonorepoBuildTooling(
withBundleAnalyzer({
middleware: [
sessionMiddleware({
isAuthorized: simpleRolesIsAuthorized,
// sessionExpiryMinutes: 4,
}),
],
cli: {
clearConsoleOnBlitzDev: false,
},
log: {
// level: "trace",
},
experimental: {
isomorphicResolverImports: false,
},
/*
module.exports = withBundleAnalyzer({
middleware: [
sessionMiddleware({
isAuthorized: simpleRolesIsAuthorized,
// sessionExpiryMinutes: 4,
}),
],
cli: {
clearConsoleOnBlitzDev: false,
},
log: {
// level: "trace",
},
experimental: {
isomorphicResolverImports: false,
},
/*
webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
Expand All @@ -34,5 +32,4 @@ module.exports = withMonorepoBuildTooling(
return config
},
*/
}),
)
})
5 changes: 2 additions & 3 deletions examples/custom-server/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {sessionMiddleware, simpleRolesIsAuthorized} = require("blitz")
const withMonorepoBuildTooling = require("@preconstruct/next")

module.exports = withMonorepoBuildTooling({
module.exports = {
middleware: [
sessionMiddleware({
isAuthorized: simpleRolesIsAuthorized,
Expand All @@ -15,4 +14,4 @@ module.exports = withMonorepoBuildTooling({
return config
},
*/
})
}
5 changes: 2 additions & 3 deletions examples/fauna/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { sessionMiddleware, simpleRolesIsAuthorized } = require("blitz")
const withMonorepoBuildTooling = require("@preconstruct/next")
const { GraphQLClient, gql } = require("graphql-request")

const graphQLClient = new GraphQLClient("https://graphql.fauna.com/graphql", {
Expand All @@ -18,7 +17,7 @@ const normalizeSession = (faunaSession) => {
}
}

module.exports = withMonorepoBuildTooling({
module.exports = {
middleware: [
sessionMiddleware({
isAuthorized: simpleRolesIsAuthorized,
Expand Down Expand Up @@ -159,4 +158,4 @@ module.exports = withMonorepoBuildTooling({
return config
},
*/
})
}
6 changes: 2 additions & 4 deletions examples/no-prisma/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const withMonorepoBuildTooling = require("@preconstruct/next")

module.exports = withMonorepoBuildTooling({
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
Expand All @@ -12,4 +10,4 @@ module.exports = withMonorepoBuildTooling({
// Important: return the modified config
return config
},
})
}
6 changes: 2 additions & 4 deletions examples/static/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const withMonorepoBuildTooling = require("@preconstruct/next")

module.exports = withMonorepoBuildTooling({
module.exports = {
middleware: [],
/* Uncomment this to customize the webpack config
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
Expand All @@ -10,4 +8,4 @@ module.exports = withMonorepoBuildTooling({
return config
},
*/
})
}
6 changes: 2 additions & 4 deletions examples/store/blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const withMonorepoBuildTooling = require("@preconstruct/next")

module.exports = withMonorepoBuildTooling({
module.exports = {
middleware: [
(req, res, next) => {
res.blitzCtx.referer = req.headers.referer
Expand All @@ -24,4 +22,4 @@ module.exports = withMonorepoBuildTooling({
// // Important: return the modified config
// return config
// },
})
}
37 changes: 37 additions & 0 deletions jest-unit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const {jsWithBabel: tsjPreset} = require("ts-jest/preset")

module.exports = {
testEnvironment: "node",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["<rootDir>/tmp", "<rootDir>/dist", "<rootDir>/templates"],
moduleNameMapper: {},
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
transform: {
...tsjPreset.transform,
},
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
testMatch: ["<rootDir>/**/*.(spec|test).{ts,tsx,js,jsx}"],
testURL: "http://localhost",
// watchPlugins: [
// require.resolve("jest-watch-typeahead/filename"),
// require.resolve("jest-watch-typeahead/testname"),
// ],
coverageReporters: ["json", "lcov", "text", "clover"],
// collectCoverage: !!`Boolean(process.env.CI)`,
collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"],
coveragePathIgnorePatterns: ["/templates/"],
// coverageThreshold: {
// global: {
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// },
// },
globals: {
"ts-jest": {
tsconfig: __dirname + "/tsconfig.test.json",
isolatedModules: true,
},
},
}
43 changes: 8 additions & 35 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
const {jsWithBabel: tsjPreset} = require("ts-jest/preset")

module.exports = {
testEnvironment: "node",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["<rootDir>/tmp", "<rootDir>/dist", "<rootDir>/templates"],
moduleNameMapper: {},
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
transform: {
...tsjPreset.transform,
},
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
testMatch: ["<rootDir>/**/*.(spec|test).{ts,tsx,js,jsx}"],
testURL: "http://localhost",
// watchPlugins: [
// require.resolve("jest-watch-typeahead/filename"),
// require.resolve("jest-watch-typeahead/testname"),
// ],
coverageReporters: ["json", "lcov", "text", "clover"],
// collectCoverage: !!`Boolean(process.env.CI)`,
collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"],
coveragePathIgnorePatterns: ["/templates/"],
// coverageThreshold: {
// global: {
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// },
// },
globals: {
"ts-jest": {
tsconfig: __dirname + "/tsconfig.test.json",
isolatedModules: true,
},
},
testMatch: ["**/*.test.js", "**/*.test.ts"],
verbose: true,
rootDir: "test",
modulePaths: ["<rootDir>/lib"],
globalSetup: "<rootDir>/jest-global-setup.js",
globalTeardown: "<rootDir>/jest-global-teardown.js",
setupFilesAfterEnv: ["<rootDir>/jest-setup-after-env.js"],
testEnvironment: "<rootDir>/jest-environment.js",
}
2 changes: 1 addition & 1 deletion nextjs/packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dev": "taskr",
"release": "taskr release",
"prepublish": "npm run release && yarn types",
"types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"types": "rimraf \"dist/**/*.d.ts\" && tsc --declaration --emitDeclarationOnly --declarationDir dist",
"typescript": "tsc --noEmit --declaration",
"ncc-compiled": "ncc cache clean && taskr ncc"
},
Expand Down
6 changes: 3 additions & 3 deletions nextjs/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function main() {
tests = (
await glob('**/*.test.js', {
nodir: true,
cwd: path.join(__dirname, 'test'),
cwd: path.join(process.cwd(), 'test'),
})
).filter((test) => {
// only include the specified type
Expand All @@ -79,7 +79,7 @@ async function main() {
if (outputTimings && groupArg) {
console.log('Fetching previous timings data')
try {
const timingsFile = path.join(__dirname, 'test-timings.json')
const timingsFile = path.join(process.cwd(), 'test-timings.json')
try {
prevTimings = JSON.parse(await fs.readFile(timingsFile, 'utf8'))
console.log('Loaded test timings from disk successfully')
Expand Down Expand Up @@ -234,7 +234,7 @@ async function main() {
} catch (err) {
if (i < NUM_RETRIES) {
try {
const testDir = path.dirname(path.join(__dirname, test))
const testDir = path.dirname(path.join(process.cwd(), test))
console.log('Cleaning test files at', testDir)
await exec(`git clean -fdx "${testDir}"`)
await exec(`git checkout "${testDir}"`)
Expand Down
Loading