|
| 1 | +/* eslint-disable no-console */ |
| 2 | +/* eslint-disable no-restricted-imports */ |
| 3 | +import {authFixture as test} from '../setup/auth.js' |
| 4 | +import {requireEnv} from '../setup/env.js' |
| 5 | +import {expect} from '@playwright/test' |
| 6 | +import * as path from 'path' |
| 7 | +import * as fs from 'fs' |
| 8 | +import {fileURLToPath} from 'url' |
| 9 | + |
| 10 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 11 | +const INVALID_TOMLS_DIR = path.join(__dirname, '../data/invalid-tomls') |
| 12 | + |
| 13 | +const invalidTomls = fs.readdirSync(INVALID_TOMLS_DIR).filter((file) => file.endsWith('.toml')) |
| 14 | + |
| 15 | +test.describe('TOML config invalid', () => { |
| 16 | + for (const tomlFile of invalidTomls) { |
| 17 | + const label = tomlFile.replace('.toml', '') |
| 18 | + |
| 19 | + test(`deploy rejects invalid toml: ${label}`, async ({cli, env}) => { |
| 20 | + requireEnv(env, 'clientId') |
| 21 | + |
| 22 | + // Set up temp dir with invalid toml + minimal package.json |
| 23 | + const appDir = fs.mkdtempSync(path.join(env.tempDir, `invalid-toml-${label}-`)) |
| 24 | + try { |
| 25 | + const toml = fs |
| 26 | + .readFileSync(path.join(INVALID_TOMLS_DIR, tomlFile), 'utf8') |
| 27 | + .replace('__E2E_CLIENT_ID__', env.clientId) |
| 28 | + fs.writeFileSync(path.join(appDir, 'shopify.app.toml'), toml) |
| 29 | + fs.writeFileSync( |
| 30 | + path.join(appDir, 'package.json'), |
| 31 | + JSON.stringify({name: `invalid-${label}`, version: '1.0.0', private: true}), |
| 32 | + ) |
| 33 | + |
| 34 | + const result = await cli.exec(['app', 'deploy', '--path', appDir, '--force'], { |
| 35 | + timeout: 2 * 60 * 1000, |
| 36 | + }) |
| 37 | + const output = result.stdout + result.stderr |
| 38 | + console.log(`[${label}] exit code: ${result.exitCode}\n[${label}] output:\n${output}`) |
| 39 | + expect(result.exitCode, `expected deploy to fail for ${label}, but it succeeded:\n${output}`).not.toBe(0) |
| 40 | + } finally { |
| 41 | + fs.rmSync(appDir, {recursive: true, force: true}) |
| 42 | + } |
| 43 | + }) |
| 44 | + } |
| 45 | +}) |
0 commit comments