Skip to content

Commit

Permalink
Improvements (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 31, 2023
2 parents 871e229 + 0b9e73e commit 69fbf7c
Show file tree
Hide file tree
Showing 52 changed files with 2,024 additions and 1,140 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ testem.log
# System Files
.DS_Store
Thumbs.db

.nx/cache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

/dist
/coverage

/.nx/cache
29 changes: 13 additions & 16 deletions e2e/gcp-deployment-manager-e2e/tests/gcp-deployment-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import {
checkFilesExist,
ensureNxProject,
runNxCommandAsync,
uniq
runNxCommandAsync
} from '@nx/plugin/testing'
import { ensureNxProject } from '../../utils/workspace'

describe('gcp-deployment-manager e2e', () => {
beforeEach(() => {
ensureNxProject(
'@nx-extend/gcp-deployment-manager',
'dist/packages/gcp-deployment-manager'
)
beforeAll(() => {
ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/gcp-deployment-manager:dist/packages/gcp-deployment-manager'
])
})

it('should be able to generate an deployment manager app', async () => {
const plugin = uniq('gcp-deployment-manager')
const appName = 'deployment-manager'

await runNxCommandAsync(
`generate @nx-extend/gcp-deployment-manager:init ${plugin}`
)
it('should be able to generate an deployment manager app', async () => {
await runNxCommandAsync(`generate @nx-extend/gcp-deployment-manager:init ${appName}`)

expect(() =>
checkFilesExist(`apps/${plugin}/src/deployment.yml`)
).not.toThrow()
expect(() => checkFilesExist(
`${appName}/src/deployment.yml`
)).not.toThrow()
}, 300000)
})
77 changes: 33 additions & 44 deletions e2e/gcp-functions-e2e/tests/gcp-functions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,55 @@
import {
checkFilesExist,
ensureNxProject,
runNxCommandAsync,
uniq
rmDist,
runNxCommandAsync
} from '@nx/plugin/testing'
import { ensureNxProject } from '../../utils/workspace'

describe('(e2e) gcp-functions', () => {
beforeEach(() => {
ensureNxProject('@nx-extend/gcp-functions', 'dist/packages/gcp-functions')
beforeAll(() => {
ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/gcp-functions:dist/packages/gcp-functions'
])
})

const appName = 'test-function'

it('should be able to generate an empty function', async () => {
const plugin = uniq('gcp-functions')
await runNxCommandAsync(`generate @nx-extend/gcp-functions:init ${plugin}`)
await runNxCommandAsync(`generate @nx-extend/gcp-functions:init ${appName}`)

expect(() =>
checkFilesExist(
`apps/${plugin}/src/main.ts`,
`apps/${plugin}/src/environments/production.yaml`
)
).not.toThrow()
expect(() => checkFilesExist(
`${appName}/src/main.ts`,
`${appName}/src/environments/production.yaml`
)).not.toThrow()
}, 300000)

it('should be able to build a function', async () => {
const plugin = uniq('gcp-functions')
await runNxCommandAsync(`generate @nx-extend/gcp-functions:init ${plugin}`)
await runNxCommandAsync(`build ${plugin}`)
await runNxCommandAsync(`build ${appName}`)

expect(() =>
checkFilesExist(
`dist/apps/${plugin}/main.js`,
`dist/apps/${plugin}/package.json`
)
).not.toThrow()
expect(() => checkFilesExist(
`dist/${appName}/main.js`,
`dist/${appName}/package.json`
)).not.toThrow()
}, 300000)

it('should be able to build a function and generate lock file', async () => {
const plugin = uniq('gcp-functions-lock-file')
await runNxCommandAsync(`generate @nx-extend/gcp-functions:init ${plugin}`)
await runNxCommandAsync(`build ${plugin} --generateLockFile`)

expect(() =>
checkFilesExist(
`dist/apps/${plugin}/main.js`,
`dist/apps/${plugin}/package.json`,
`dist/apps/${plugin}/package-lock.json`
)
).not.toThrow()
rmDist()
await runNxCommandAsync(`build ${appName} --generateLockFile`)

expect(() => checkFilesExist(
`dist/${appName}/main.js`,
`dist/${appName}/package.json`,
`dist/${appName}/yarn.lock`
)).not.toThrow()
}, 300000)

it('should be able the runner', async () => {
const plugin = uniq('gcp-functions-runner')
await runNxCommandAsync(
`generate @nx-extend/gcp-functions:init-runner ${plugin}`
)
const runnerName = 'functions-runner'
await runNxCommandAsync(`generate @nx-extend/gcp-functions:init-runner ${runnerName}`)

expect(() =>
checkFilesExist(
`apps/${plugin}/src/main.ts`,
`apps/${plugin}/src/__runner.controller.ts`,
`apps/${plugin}/src/__runner.module.ts`
)
).not.toThrow()
expect(() => checkFilesExist(
`${runnerName}/src/main.ts`
)).not.toThrow()
}, 300000)
})
26 changes: 14 additions & 12 deletions e2e/gcp-secrets-e2e/tests/gcp-secrets.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import {
checkFilesExist,
ensureNxProject,
runNxCommandAsync,
uniq
} from '@nx/plugin/testing'

import { ensureNxProject } from '../../utils/workspace'

describe('gcp-secrets e2e', () => {
beforeEach(() => {
ensureNxProject('@nx-extend/gcp-secrets', 'dist/packages/gcp-secrets')
beforeAll(() => {
ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/gcp-secrets:dist/packages/gcp-secrets'
])
})

it('should be able to generate an secrets app', async () => {
const plugin = uniq('gcp-functions')
const appName = uniq('gcp-secrets')

await runNxCommandAsync(`generate @nx-extend/gcp-secrets:init ${plugin}`)
it('should be able to generate an secrets app', async () => {
await runNxCommandAsync(`generate @nx-extend/gcp-secrets:init ${appName}`)

expect(() =>
checkFilesExist(
`apps/${plugin}/src/secret-one.json`,
`apps/${plugin}/src/secret-two.json`
)
).not.toThrow()
expect(() => checkFilesExist(
`${appName}/src/secret-one.json`,
`${appName}/src/secret-two.json`
)).not.toThrow()
}, 300000)
})
50 changes: 27 additions & 23 deletions e2e/translations-e2e/tests/translations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import {
ensureNxProject,
runNxCommandAsync,
readJson,
updateFile
} from '@nx/plugin/testing'
import { ensureNxProject } from '../../utils/workspace'

describe('translations e2e', () => {
beforeEach(() => {
ensureNxProject('@nx-extend/translations', 'dist/packages/translations')
beforeAll(() => {
ensureNxProject([
'@nx-extend/core:dist/packages/core',
'@nx-extend/translations:dist/packages/translations'
])
})

const appName = 'translations'
it('should be able to add', async () => {
await runNxCommandAsync(
'generate @nx/react:app test-app --style=css --no-interactive'
)
await runNxCommandAsync('generate @nx-extend/translations:add test-app')
await runNxCommandAsync(`generate @nx/react:app ${appName} --no-interactive --e2eTestRunner=none`)
await runNxCommandAsync(`generate @nx-extend/translations:add ${appName}`)

expect(readJson('apps/test-app/project.json').targets).toEqual(
expect(readJson(`${appName}/project.json`).targets).toEqual(
expect.objectContaining({
'extract-translations': {
executor: '@nx-extend/translations:extract',
Expand All @@ -37,9 +39,9 @@ describe('translations e2e', () => {
})
)

expect(readJson('apps/test-app/.translationsrc.json')).toEqual({
extends: '../../.translationsrc.json',
projectName: 'test-app'
expect(readJson(`${appName}/.translationsrc.json`)).toEqual({
extends: '../.translationsrc.json',
projectName: appName
})

expect(readJson('.translationsrc.json')).toEqual({
Expand All @@ -54,17 +56,19 @@ describe('translations e2e', () => {
}, 300000)

it('should be able to extract translations', async () => {
await runNxCommandAsync(
'generate @nx/react:app test-app --style=css --no-interactive'
)
await runNxCommandAsync('generate @nx-extend/translations:add test-app')

updateFile(
'apps/test-app/src/app/app.tsx',
`${appName}/src/app/app.tsx`,
`
import { FormattedMessage } from 'react-intl'
import { FormattedMessage, useIntl } from 'react-intl'
export function App() {
const intl = useIntl()
console.log(intl.formatMessage({
id: 'message-id-2',
defaultMessage: 'Message 2'
}))
return (
<div>
<FormattedMessage
Expand All @@ -75,13 +79,13 @@ describe('translations e2e', () => {
}
export default App
`
)
`)

await runNxCommandAsync('extract-translations test-app')
await runNxCommandAsync(`extract-translations ${appName}`)

expect(readJson('apps/test-app/src/translations/en.json')).toEqual({
'message-id': 'Message'
expect(readJson(`${appName}/src/translations/en.json`)).toEqual({
'message-id': 'Message',
'message-id-2': 'Message 2'
})
}, 300000)
})
47 changes: 47 additions & 0 deletions e2e/utils/workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { execSync } from 'child_process'
import { dirname } from 'path'
import { cleanup, patchPackageJsonForPlugin, tmpProjPath } from '@nx/plugin/testing'
import { mkdirSync } from 'fs'

function runNxNewCommand(localTmpDir: string) {
return execSync(
`node ${require.resolve(
'nx'
)} new proj --nx-workspace-root=${localTmpDir} --no-interactive --skip-install --collection=@nx/workspace --npmScope=proj --preset=apps`,
{
cwd: localTmpDir
}
)
}

/**
* Ensures that a project has been setup in the e2e directory
* It will also copy `@nx` packages to the e2e directory
*/
export function ensureNxProject(patchPlugins: string[] = []): void {
cleanup()

const tmpProjectPath = tmpProjPath()
const tmpProjectDir = dirname(tmpProjectPath)
mkdirSync(tmpProjectDir, {
recursive: true
})
runNxNewCommand(tmpProjectDir)

for (const plugin of patchPlugins) {
const [npmPackageName, pluginDistPath] = plugin.split(':')
patchPackageJsonForPlugin(npmPackageName, pluginDistPath)
}

execSync('touch yarn.lock', {
cwd: tmpProjectPath,
stdio: 'inherit',
env: process.env
})
execSync('yarn', {
cwd: tmpProjectPath,
stdio: 'inherit',
env: process.env
})
}

23 changes: 14 additions & 9 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"npmScope": "nx-extend",
"affected": {
"defaultBase": "master"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx-cloud",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"],
"accessToken": "ZGQ5Y2MwYjUtMjA2MS00NDEwLTgzZmQtYzE0MTUwNTMwMzFmfHJlYWQtd3JpdGU=",
"canTrackAnalytics": false,
"showUsageWarnings": true,
"parallel": 1
"showUsageWarnings": true
}
}
},
Expand All @@ -23,15 +18,25 @@
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
"inputs": ["production", "^production"],
"cache": true
},
"test": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"cache": true
},
"lint": {
"cache": true
},
"e2e": {
"cache": true
}
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"sharedGlobals": [],
"production": ["default", "!{projectRoot}/src/test-setup.[jt]s"]
}
},
"nxCloudAccessToken": "ZGQ5Y2MwYjUtMjA2MS00NDEwLTgzZmQtYzE0MTUwNTMwMzFmfHJlYWQtd3JpdGU=",
"parallel": 1
}
Loading

0 comments on commit 69fbf7c

Please sign in to comment.