Source: test-suite-dto.js

import TestDTO from './test-dto.js'

/**
 *
 */
class TestSuiteDTO {
  /**
   *
   * @param {any} json
   * @returns {TestSuiteDTO}
   */
  static fromJSON (json) {
    const suite = new TestSuiteDTO(json.name, json.configuration, json.yaml, json.id)
    if (json.tests) {
      suite.tests = json.tests.map(t => new TestDTO(t))
    }
    return suite
  }

  /**
   * @param {string} name
   * @param {string} configurationFile
   * @param {string} yamlFile
   * @returns {TestSuiteDTO}
   */
  static fromFiles (name, configurationFile, yamlFile) {
    const fs = require('fs')
    if (!fs.existsSync(configurationFile)) {
      throw new Error('Configuration file not found: ' + configurationFile)
    }
    const configurationContents = fs.readFileSync(configurationFile, 'utf-8')
    if (!fs.existsSync(yamlFile)) {
      throw new Error('Test file not found: ' + yamlFile)
    }
    const yamlContents = fs.readFileSync(yamlFile, 'utf-8')
    const configuration = JSON.parse(configurationContents)
    return new TestSuiteDTO(name, configuration, yamlContents)
  }

  /**
   * @param {string} name
   * @param {any} configuration
   * @param {string} yaml
   * @param {string | undefined} id
   */
  constructor (name, configuration, yaml, id = undefined) {
    this.name = name
    this.configuration = configuration
    this.yaml = yaml
    this.id = id
    /** @type {TestDTO[] | undefined} */
    this.tests = undefined
  }
}

export default TestSuiteDTO