-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix projectname for subdir projects * Regress to Nx v13.10.6 * Regress to Nx v13.10.6 * patch workspace root for generators also * docs tweaks * fix e2e test bug * add testbed e2e project * Add e2e testbed * e2e testbed updates * Log e2e testbed * e2e testbed improvements * improved compat testing * compat test tweaks * yet more tests * more compat test improvements * I think this will be worth the effort * More compat test tweaks * Rename testbed -> compat * more cleanup/refactor of compat tests * move jest-ish functions to own module * refactor compat utils layout * All e2e compat tests passing 13.10.6 plugin build * add comments * so sick of this now, Nx is a hot mess across versions. * minor tweaks to the plugin * move to node 16, install legacy plugin with `--legacy-peer-deps` * fix bug in action
- Loading branch information
Showing
52 changed files
with
5,978 additions
and
11,472 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ on: | |
|
||
jobs: | ||
release: | ||
needs: [publish_github, publish_npm] | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
|
||
e2e.log |
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 |
---|---|---|
@@ -1 +1 @@ | ||
19.1.0 | ||
16.19.0 |
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,3 @@ | ||
14.20.0 | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Plugin Versions | ||
|
||
- Plugin versions will be matched to Nx versions - eg. 13.10.6 | ||
- There will be a release/v13.10.6 branch for each release that will allow patching if necessary | ||
|
||
- `release/v13.10.6` -> Compatible with Nx 13.10.6 | ||
|
||
Unit testing | ||
|
||
Can we create a bunch of skeleton workspaces that we run tests on? | ||
|
||
eg. | ||
|
||
- `/compat` | ||
- `/13.10.6` | ||
- `/14.0.0` | ||
|
||
Each of these is a blank workspace. We can gitignore everything. | ||
|
||
Maybe we just create the workspaces in a script. What do we need? | ||
|
||
1. `npm ci` the workspace | ||
2. Build the plugin | ||
3. `npx [email protected] --preset=apps` | ||
4. Add a local ref to the plugin | ||
5. Generate a firebase app - check it builds | ||
6. Generate a lib - check it builds | ||
7. Add the lib as an import - check it builds | ||
8. Modify the firebaserc with our secret firebase project | ||
9. Check it deploys | ||
|
||
Do this for each node version we want - 14, 16, 18 | ||
Do this for each Nx version we want - 13 | ||
We can check that old plugin versions work with newer Nx: | ||
|
||
- Plugin v13 check against Nx 13,14,15, for Node 14,16,18 | ||
- Plugin v14 check against Nx 14,15, for Node 14,16,18 | ||
- Plugin v15 check against Nx 15, for Node 14,16,18 |
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 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,15 @@ | ||
module.exports = { | ||
displayName: 'compat', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/e2e/compat', | ||
} |
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,52 @@ | ||
{ | ||
"root": "e2e/compat", | ||
"sourceRoot": "e2e/compat/src", | ||
"projectType": "application", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/node:webpack", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/e2e/compat", | ||
"main": "e2e/compat/src/main.ts", | ||
"tsConfig": "e2e/compat/tsconfig.app.json", | ||
"assets": ["e2e/compat/src/assets"] | ||
}, | ||
"configurations": { | ||
"production": { | ||
"optimization": true, | ||
"extractLicenses": true, | ||
"inspect": false, | ||
"fileReplacements": [ | ||
{ | ||
"replace": "e2e/compat/src/environments/environment.ts", | ||
"with": "e2e/compat/src/environments/environment.prod.ts" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"serve": { | ||
"executor": "@nrwl/node:node", | ||
"options": { | ||
"buildTarget": "compat:build" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["e2e/compat/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/e2e/compat"], | ||
"options": { | ||
"jestConfig": "e2e/compat/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
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,68 @@ | ||
// setup re-usable workspaces for e2e testbed | ||
import { customExec } from './utils/exec' | ||
import { green, info, log, red, setLogFile } from './utils/log' | ||
import { | ||
deleteDir, | ||
deleteFile, | ||
ensureDir, | ||
fileExists, | ||
setCwd, | ||
} from './utils/utils' | ||
import { createTestDir, createWorkspace } from './workspace' | ||
import { Cache } from './utils/cache' | ||
|
||
/** | ||
* Generate an NxWorkspace with the given versions and gzip it | ||
* unless the gzip archive of a version already exists | ||
* @param nxVersion - target nx version eg. '13.10.6' | ||
* @param pluginVersion - target nx-firebase version eg. '0.3.4' | ||
* @param force - always recreate the workspace | ||
*/ | ||
export async function setupNxWorkspace(cache: Cache, force = false) { | ||
try { | ||
// setup the target Nx workspace | ||
const archiveExists = fileExists(cache.archiveFile) && !force | ||
|
||
info( | ||
`SETUP NX VERSION '${cache.nxVersion}' WITH PLUGIN VERSION '${ | ||
cache.pluginVersion | ||
}' ${archiveExists ? '[CACHED]' : 'INSTALLING'}\n`, | ||
) | ||
|
||
ensureDir(cache.rootDir) | ||
|
||
setLogFile(`${cache.rootDir}/${cache.nxVersion}.log.txt`) | ||
|
||
log( | ||
`Creating new Nx workspace version ${cache.nxVersion} in directory '${cache.testDir}'`, | ||
) | ||
|
||
// create workspace & archive if it doesn't already exist | ||
if (!archiveExists) { | ||
deleteDir(cache.testDir) | ||
createTestDir(cache.testDir) | ||
await createWorkspace(cache) | ||
|
||
// delete any existing archive file so we do not accidentally append to archive | ||
if (fileExists(cache.archiveFile)) { | ||
deleteFile(cache.archiveFile) | ||
} | ||
|
||
// cwd is workspaceDir | ||
setCwd(cache.rootDir) | ||
// archive the workspace | ||
await customExec(`tar -zcf ${cache.archiveFile} ./${cache.nxVersion}`) // add -v for verbose | ||
deleteDir(cache.testDir) | ||
} else { | ||
log( | ||
`WQokspace archive '${cache.archiveFile}' already exists for '${cache.workspaceDir}', no setup required`, | ||
) | ||
} | ||
info(green(`SETUP VERSION '${cache.nxVersion}' SUCCEEDED\n`)) | ||
} catch (err) { | ||
info(err.message) | ||
info(red(`SETUP VERSION '${cache.nxVersion}' FAILED\n`)) | ||
// escalate, this is a show stopper | ||
throw err | ||
} | ||
} |
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,125 @@ | ||
import { Cache, getCache } from './utils/cache' | ||
import { customExec, runNxCommandAsync } from './utils/exec' | ||
import { expectToContain, expectToNotContain, it } from './utils/jest-ish' | ||
import { green, info, red, setLogFile, time } from './utils/log' | ||
import { addContentToTextFile, deleteDir, setCwd } from './utils/utils' | ||
import { installPlugin } from './workspace' | ||
|
||
const npmContent = [ | ||
`Added 'npm' dependency 'firebase-admin'`, | ||
`Added 'npm' dependency 'firebase-functions'`, | ||
] | ||
|
||
const libContent = [`Copied 'lib' dependency '@myorg/lib1'`] | ||
|
||
const importMatch = `import * as functions from "firebase-functions";` | ||
|
||
const notCachedMatch = `[existing outputs match the cache, left as is]` | ||
|
||
export async function testPlugin(workspaceDir: string) { | ||
const indexTsPath = `${workspaceDir}/apps/functions/src/index.ts` | ||
|
||
await runNxCommandAsync('g @simondotm/nx-firebase:app functions') | ||
await runNxCommandAsync( | ||
'g @nrwl/js:lib lib1 --buildable --importPath="@myorg/lib1"', | ||
) | ||
|
||
await it('should build the lib', async () => { | ||
await runNxCommandAsync('build lib1') | ||
}) | ||
|
||
await it('should build the functions', async () => { | ||
const { stdout } = await runNxCommandAsync('build functions') | ||
expectToNotContain(stdout, npmContent) | ||
expectToNotContain(stdout, libContent) | ||
}) | ||
|
||
await it('should update index.ts so that deps are updated after creation', async () => { | ||
addContentToTextFile(indexTsPath, importMatch, '// comment added') | ||
const { stdout } = await runNxCommandAsync('build functions') | ||
expectToContain(stdout, npmContent) | ||
expectToNotContain(stdout, libContent) | ||
}) | ||
|
||
await it('should add a lib dependency', async () => { | ||
const importAddition = `import { lib1 } from '@myorg/lib1'\nconsole.log(lib1())\n` | ||
addContentToTextFile(indexTsPath, importMatch, importAddition) | ||
const { stdout } = await runNxCommandAsync('build functions') | ||
expectToContain(stdout, npmContent) | ||
expectToContain(stdout, libContent) | ||
}) | ||
|
||
// TODO: other checks | ||
// - check package.json contains the deps | ||
// - check package.json has the right node engine | ||
// - check all the files exist | ||
// - check the firebase config looks legit | ||
// - if possible, run a test deploy? | ||
// - check the init generator installs the firebase deps | ||
// - check the plugin peerdeps installs the @nrwl/js and @nrwl/devkit and @nrwl/node deps | ||
} | ||
|
||
export function clean() { | ||
const cache = getCache('', '') | ||
info(red(`Cleaning compat test cache dir '${cache.rootDir}'`)) | ||
deleteDir(cache.rootDir) | ||
} | ||
|
||
export async function testNxVersion(cache: Cache) { | ||
let error: string | undefined | ||
|
||
const t = Date.now() | ||
|
||
setLogFile(`${cache.rootDir}/${cache.nxVersion}.e2e.txt`) | ||
|
||
try { | ||
info( | ||
`TESTING NX VERSION '${cache.nxVersion}' AGAINST PLUGIN VERSION '${cache.pluginVersion}'\n`, | ||
) | ||
|
||
// cleanup | ||
setCwd(cache.rootDir) | ||
deleteDir(cache.testDir) | ||
|
||
// unpack the archive | ||
setCwd(cache.rootDir) | ||
await customExec(`tar -xzf ${cache.archiveFile}`) // add -v for verbose | ||
|
||
setCwd(cache.workspaceDir) | ||
|
||
if (cache.deferPluginInstall) { | ||
// lets see if installing the plugin in the test suite | ||
// makes things more stable... | ||
await installPlugin(cache) | ||
} | ||
|
||
// run the plugin test suite | ||
await testPlugin(cache.workspaceDir) | ||
|
||
info(green(`TESTING VERSION '${cache.nxVersion}' SUCCEEDED\n`)) | ||
} catch (err) { | ||
info(err.message) | ||
info( | ||
red( | ||
`TESTING VERSION '${cache.nxVersion}' FAILED - INCOMPATIBILITY DETECTED\n`, | ||
), | ||
) | ||
error = err.message | ||
} | ||
|
||
// pretty sure there's nothing but trouble doing this | ||
// if (cache.disableDaemon) { | ||
// stop nx daemon after the test to stop connection in use errors | ||
// await runNxCommandAsync(`reset`) | ||
// } | ||
|
||
// cleanup | ||
setCwd(cache.rootDir) | ||
|
||
deleteDir(cache.testDir) | ||
|
||
const dt = Date.now() - t | ||
info(`Completed in ${time(dt)}\n`) | ||
|
||
return error | ||
} |
Oops, something went wrong.