Add utilities to check platform to determine if a test should run (#5983)
* Add tests for utility to bypass unreliable tests * Limit skip to just Windows * Ignore unit tests from Playwright * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										4
									
								
								.github/workflows/static-analysis.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/static-analysis.yml
									
									
									
									
										vendored
									
									
								
							@ -141,13 +141,13 @@ jobs:
 | 
			
		||||
        if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
 | 
			
		||||
        run: yarn playwright install chromium --with-deps
 | 
			
		||||
 | 
			
		||||
      - name: run unit tests
 | 
			
		||||
      - name: Run unit tests
 | 
			
		||||
        if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
 | 
			
		||||
        run: xvfb-run -a yarn test:unit
 | 
			
		||||
        env:
 | 
			
		||||
          VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
 | 
			
		||||
 | 
			
		||||
      - name: check for changes
 | 
			
		||||
      - name: Check for changes
 | 
			
		||||
        if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
 | 
			
		||||
        id: git-check
 | 
			
		||||
        run: |
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ import {
 | 
			
		||||
  executorInputPath,
 | 
			
		||||
  getUtils,
 | 
			
		||||
  orRunWhenFullSuiteEnabled,
 | 
			
		||||
  runningOnWindows,
 | 
			
		||||
} from './test-utils'
 | 
			
		||||
import { join } from 'path'
 | 
			
		||||
import { FILE_EXT } from 'lib/constants'
 | 
			
		||||
@ -15,7 +16,9 @@ test.describe('integrations tests', () => {
 | 
			
		||||
    'Creating a new file or switching file while in sketchMode should exit sketchMode',
 | 
			
		||||
    { tag: '@electron' },
 | 
			
		||||
    async ({ page, context, homePage, scene, editor, toolbar, cmdBar }) => {
 | 
			
		||||
      test.fixme(orRunWhenFullSuiteEnabled())
 | 
			
		||||
      if (runningOnWindows()) {
 | 
			
		||||
        test.fixme(orRunWhenFullSuiteEnabled())
 | 
			
		||||
      }
 | 
			
		||||
      await context.folderSetupFn(async (dir) => {
 | 
			
		||||
        const bracketDir = join(dir, 'test-sample')
 | 
			
		||||
        await fsp.mkdir(bracketDir, { recursive: true })
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 143 KiB  | 
							
								
								
									
										96
									
								
								e2e/playwright/test-utils.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								e2e/playwright/test-utils.test.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,96 @@
 | 
			
		||||
import {
 | 
			
		||||
  runningOnLinux,
 | 
			
		||||
  runningOnMac,
 | 
			
		||||
  runningOnWindows,
 | 
			
		||||
  orRunWhenFullSuiteEnabled,
 | 
			
		||||
} from './test-utils'
 | 
			
		||||
 | 
			
		||||
describe('platform detection utilities', () => {
 | 
			
		||||
  const originalPlatform = process.platform
 | 
			
		||||
 | 
			
		||||
  afterAll(() => {
 | 
			
		||||
    Object.defineProperty(process, 'platform', {
 | 
			
		||||
      value: originalPlatform,
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  describe('runningOnLinux', () => {
 | 
			
		||||
    it('returns true on Linux', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'linux',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnLinux()).toBe(true)
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    it('returns false on other platforms', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'darwin',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnLinux()).toBe(false)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  describe('runningOnMac', () => {
 | 
			
		||||
    it('returns true on Mac', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'darwin',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnMac()).toBe(true)
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    it('returns false on other platforms', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'linux',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnMac()).toBe(false)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  describe('runningOnWindows', () => {
 | 
			
		||||
    it('returns true on Windows', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'win32',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnWindows()).toBe(true)
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    it('returns false on other platforms', () => {
 | 
			
		||||
      Object.defineProperty(process, 'platform', {
 | 
			
		||||
        value: 'linux',
 | 
			
		||||
      })
 | 
			
		||||
      expect(runningOnWindows()).toBe(false)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
describe('utility to bypass unreliable tests', () => {
 | 
			
		||||
  const originalEnv = { ...process.env }
 | 
			
		||||
 | 
			
		||||
  afterAll(() => {
 | 
			
		||||
    process.env = { ...originalEnv }
 | 
			
		||||
  })
 | 
			
		||||
  it('always runs them on dedicated branch', () => {
 | 
			
		||||
    process.env.GITHUB_EVENT_NAME = 'push'
 | 
			
		||||
    process.env.GITHUB_REF = 'refs/heads/all-e2e'
 | 
			
		||||
    process.env.GITHUB_HEAD_REF = ''
 | 
			
		||||
    process.env.GITHUB_BASE_REF = ''
 | 
			
		||||
    const condition = orRunWhenFullSuiteEnabled()
 | 
			
		||||
    expect(condition).toBe(false)
 | 
			
		||||
  })
 | 
			
		||||
  it('skips them on the main branch', () => {
 | 
			
		||||
    process.env.GITHUB_EVENT_NAME = 'push'
 | 
			
		||||
    process.env.GITHUB_REF = 'refs/heads/main'
 | 
			
		||||
    process.env.GITHUB_HEAD_REF = ''
 | 
			
		||||
    process.env.GITHUB_BASE_REF = ''
 | 
			
		||||
    const condition = orRunWhenFullSuiteEnabled()
 | 
			
		||||
    expect(condition).toBe(true)
 | 
			
		||||
  })
 | 
			
		||||
  it('skips them on pull requests', () => {
 | 
			
		||||
    process.env.GITHUB_EVENT_NAME = 'pull_request'
 | 
			
		||||
    process.env.GITHUB_REF = 'refs/pull/5883/merge'
 | 
			
		||||
    process.env.GITHUB_HEAD_REF = 'my-branch'
 | 
			
		||||
    process.env.GITHUB_BASE_REF = 'main'
 | 
			
		||||
    const condition = orRunWhenFullSuiteEnabled()
 | 
			
		||||
    expect(condition).toBe(true)
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
@ -55,6 +55,18 @@ export const commonPoints = {
 | 
			
		||||
export const editorSelector = '[role="textbox"][data-language="kcl"]'
 | 
			
		||||
type PaneId = 'variables' | 'code' | 'files' | 'logs'
 | 
			
		||||
 | 
			
		||||
export function runningOnLinux() {
 | 
			
		||||
  return process.platform === 'linux'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function runningOnMac() {
 | 
			
		||||
  return process.platform === 'darwin'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function runningOnWindows() {
 | 
			
		||||
  return process.platform === 'win32'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function orRunWhenFullSuiteEnabled() {
 | 
			
		||||
  const branch = process.env.GITHUB_REF?.replace('refs/heads/', '')
 | 
			
		||||
  return branch !== 'all-e2e'
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,7 @@ import { defineConfig, devices } from '@playwright/test'
 | 
			
		||||
export default defineConfig({
 | 
			
		||||
  timeout: 120_000, // override the default 30s timeout
 | 
			
		||||
  testDir: './e2e/playwright',
 | 
			
		||||
  testIgnore: '*.test.ts', // ignore unit tests
 | 
			
		||||
  /* Run tests in files in parallel */
 | 
			
		||||
  fullyParallel: true,
 | 
			
		||||
  /* Fail the build on CI if you accidentally left test.only in the source code. */
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ const config = defineConfig({
 | 
			
		||||
    coverage: {
 | 
			
		||||
      provider: 'istanbul', // or 'v8'
 | 
			
		||||
    },
 | 
			
		||||
    exclude: [...configDefaults.exclude, '**/e2e/**/*', 'rust'],
 | 
			
		||||
    exclude: [...configDefaults.exclude, '**/e2e/**/*.spec.*', 'rust'],
 | 
			
		||||
    deps: {
 | 
			
		||||
      optimizer: {
 | 
			
		||||
        web: {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user