|
| 1 | +#!/usr/bin/env node |
| 2 | +// Simple test runner that avoids Node.js test runner serialization issues |
| 3 | +let create = require('../../src/index') |
| 4 | +let { join, resolve } = require('path') |
| 5 | +let { readFileSync, existsSync, rmSync, mkdirSync } = require('fs') |
| 6 | +let { updater } = require('@architect/utils') |
| 7 | + |
| 8 | +let tmp = resolve(__dirname, '..', 'tmp') |
| 9 | +let passed = 0 |
| 10 | +let failed = 0 |
| 11 | + |
| 12 | +function emptyDirSync (dir) { |
| 13 | + if (existsSync(dir)) { |
| 14 | + rmSync(dir, { recursive: true, force: true }) |
| 15 | + } |
| 16 | + mkdirSync(dir, { recursive: true }) |
| 17 | +} |
| 18 | + |
| 19 | +async function test (name, fn) { |
| 20 | + try { |
| 21 | + emptyDirSync(tmp) |
| 22 | + await fn() |
| 23 | + console.log(`✓ ${name}`) |
| 24 | + passed++ |
| 25 | + } |
| 26 | + catch (err) { |
| 27 | + console.error(`✗ ${name}`) |
| 28 | + console.error(err) |
| 29 | + failed++ |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +async function main () { |
| 34 | + console.log('Running CLI Integration Tests...\n') |
| 35 | + |
| 36 | + await test('should build the basic templated node runtime project', async () => { |
| 37 | + let update = updater('Create') |
| 38 | + await create({ folder: tmp, install: false, runtime: 'node.js', update }) |
| 39 | + if (!existsSync(join(tmp, 'src', 'http', 'get-index', 'index.mjs'))) { |
| 40 | + throw new Error('index.mjs not created') |
| 41 | + } |
| 42 | + if (!readFileSync(join(tmp, 'app.arc'), 'utf-8').match(/runtime node/)) { |
| 43 | + throw new Error('runtime node not in manifest') |
| 44 | + } |
| 45 | + }) |
| 46 | + |
| 47 | + await test('should build the basic templated deno runtime project', async () => { |
| 48 | + let update = updater('Create') |
| 49 | + await create({ folder: tmp, install: false, runtime: 'deno', update }) |
| 50 | + if (!existsSync(join(tmp, 'src', 'http', 'get-index', 'mod.ts'))) { |
| 51 | + throw new Error('mod.ts not created') |
| 52 | + } |
| 53 | + if (!readFileSync(join(tmp, 'app.arc'), 'utf-8').match(/runtime deno/)) { |
| 54 | + throw new Error('runtime deno not in manifest') |
| 55 | + } |
| 56 | + }) |
| 57 | + |
| 58 | + await test('should build the basic templated python runtime project', async () => { |
| 59 | + let update = updater('Create') |
| 60 | + await create({ folder: tmp, install: false, runtime: 'python', update }) |
| 61 | + if (!existsSync(join(tmp, 'src', 'http', 'get-index', 'lambda.py'))) { |
| 62 | + throw new Error('lambda.py not created') |
| 63 | + } |
| 64 | + if (!readFileSync(join(tmp, 'app.arc'), 'utf-8').match(/runtime python/)) { |
| 65 | + throw new Error('runtime python not in manifest') |
| 66 | + } |
| 67 | + }) |
| 68 | + |
| 69 | + await test('should build the basic templated ruby runtime project', async () => { |
| 70 | + let update = updater('Create') |
| 71 | + await create({ folder: tmp, install: false, runtime: 'ruby', update }) |
| 72 | + if (!existsSync(join(tmp, 'src', 'http', 'get-index', 'lambda.rb'))) { |
| 73 | + throw new Error('lambda.rb not created') |
| 74 | + } |
| 75 | + if (!readFileSync(join(tmp, 'app.arc'), 'utf-8').match(/runtime ruby/)) { |
| 76 | + throw new Error('runtime ruby not in manifest') |
| 77 | + } |
| 78 | + }) |
| 79 | + |
| 80 | + console.log(`\n${passed} passed, ${failed} failed`) |
| 81 | + process.exit(failed > 0 ? 1 : 0) |
| 82 | +} |
| 83 | + |
| 84 | +main() |
0 commit comments