Skip to content

Commit

Permalink
chore: add bad reference error [gh-800]
Browse files Browse the repository at this point in the history
  • Loading branch information
Nahuel Alejandro Ramos committed Aug 17, 2023
1 parent 41aaa63 commit c459c19
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const waitForNewTab = 1
export const waitForPageNavigation = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable no-console */
// Note: These must be relative imports above the checkly.config.ts location
import { waitForNewTab, waitForPageNavigation } from '../../common/__test-utils__/playwright'
import { test } from '@playwright/test'

test('login and and navigate to the provider shopfront', ({ page }) => {
console.log('ok')
page.setDefaultTimeout(10000)
console.log(waitForNewTab, waitForPageNavigation)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'checkly'

const config = defineConfig({
projectName: 'Test Project (bad reference project)',
logicalId: 'test-bad-reference-project',
repoUrl: 'https://github.com/checkly/checkly-cli',
checks: {
locations: ['us-east-1', 'eu-west-1'],
tags: ['mac'],
runtimeId: '2022.10',
checkMatch: '**/*.check.ts',
browserChecks: {
testMatch: '**/*.spec.ts',
},
},
})

export default config
13 changes: 13 additions & 0 deletions packages/cli/e2e/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ describe('test', () => {
expect(result.status).toBe(1)
})

it('Should fail with bad dependency reference', async () => {
const result = await runChecklyCli({
args: ['test'],
apiKey: config.get('apiKey'),
accountId: config.get('accountId'),
directory: path.join(__dirname, 'fixtures', 'test-bad-reference-project', 'e2e'),
})
expect(result.stderr).toContain('Error: You cannot reference a dependency file above the Checkly config')
expect(result.stderr).toContain('location folder. Please, modify')
expect(result.stderr).toContain('"../common/__test-utils__/playwright/index.ts" path.')
expect(result.status).toBe(1)
})

it('Should terminate when no checks are found', async () => {
const result = await runChecklyCli({
args: ['test', 'does-not-exist.js'],
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/constructs/browser-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ export class BrowserCheck extends Check {

const deps: CheckDependency[] = []
for (const { filePath, content } of parsed.dependencies) {
const relativePath = pathToPosix(path.relative(Session.basePath!, filePath))
if (relativePath.startsWith('..')) {
throw new Error(`You cannot reference a dependency file above the Checkly config location folder. Please, modify "${relativePath}" path.`)
}
deps.push({
path: pathToPosix(path.relative(Session.basePath!, filePath)),
path: relativePath,
content,
})
}
Expand Down

0 comments on commit c459c19

Please sign in to comment.