Skip to content

[realtime-js] Doctests are failing #3

Closed

Description

@kiwicopple

There seem to be 2 problems, not with the tests themselves but rather with the doctest library:

  1. Not correctly validating
/**
 * Converts the value of an individual column
 * @param {String} columnName The column that you want to convert
 * @param {{name: String, type: String}[]} columns All of the columns
 * @param {Object} records The map of string values
 * @param {Array} skipTypes An array of types that should not be converted
 * @return {object} Useless information
 * 
 * @example
 * convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], [])
 * //=>
 * 33
 * 
 * @example
 * convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], ['int4'])
 * //=>
 * "33"
 */
export const convertColumn = (columnName, columns, records, skipTypes) => {
  let column = columns.find(x => x.name == columnName)
  if(skipTypes.includes(column.type)) return noop(records[columnName])
  else return convertCell(column.type, records[columnName])
}

Change the "33" to 33 and it will still return true.

  1. Unable to parse file
/**
 * Takes an array of columns and an object of string values then converts each string value
 * to its mapped type
 * @param {{name: String, type: String}[]} columns
 * @param {Object} records
 * @param {Object} options The map of various options that can be applied to the mapper
 * @param {Array} options.skipTypes The array of types that should not be converted
 * 
 * @example
 * convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {'Paul', '33'}, {})
 * //=>
 * { first_name: 'Paul', age: 33 }
 */
export const convertChangeData = (columns, records, options = {}) => {
  let result = {}
  let skipTypes = typeof options.skipTypes !== 'undefined' ? options.skipTypes : []
  Object.entries(records).map(([key, value]) => {
    result[key] = convertColumn(key, columns, records, skipTypes)
  })
  return result
}

This @example is causing the library to break.


The concept of the library is awesome, so I think we should pitch in to improve it. Other likely improvements:

We should be able to add descriptions to the examples (if it fits the JSdoc spec)

/**
 * @example Add an example description here
 * convertCell('bool', 'true')
 * //=>
 * true
 */

We should be able to add descriptions to the return values (if it fits the JSdoc spec)

/**
 * @example 
 * convertCell('bool', 'true')
 * //=> Add a return value description here
 * true
 */

Activity

  1. kiwicopple commented on Nov 10, 2019

    @kiwicopple
    MemberAuthor

    Will wait for response from developer as I'm not sure about the license - MainShayne233/js-doctest#1

  2. kiwicopple commented on Nov 10, 2019

    @kiwicopple
    MemberAuthor

    Looks like it doesn't cope well with await's either. See in packages/pg-admin-js:

    /**
     * Takes an array of columns and an object of string values then converts each string value
     * to its mapped type
     * @param {string} schema The database schema containing the tables
     * @param {Object} config The database config
     * @param {string} config.host
     * @param {string} config.user
     * @param {string} config.password
     * @param {string} config.database
     * @param {number} config.port
     * @param {Object} options
     * @param {string} options.schema
     *
     * @example
     * await getAll()
     * //=>
     * [
     *    { table_schema: 'public', table_name: 'users' }
     * ]
     */
    export const getAll = async (config = {}, options = {}) => {
      const dbConfig = { ...constants.POSTGRES_CONFIG, ...config }
      const schema = options.schema || constants.DEFAULT_SCHEMA
      const conn = await postgres.connect(dbConfig)
      const results = await postgres.runQuery(conn, schema, getAllTablesSql)
      postgres.disconnect(conn)
      return results.rows
    }
  3. kiwicopple commented on Jan 30, 2020

    @kiwicopple
    MemberAuthor

    Closing this as it will be tracked in the doctest-js repo:
    kiwicopple/doctest-js#1

  4. added a commit that references this issue on Mar 29, 2021
  5. added a commit that references this issue on Sep 19, 2023
  6. added a commit that references this issue on Mar 27, 2025
  7. added a commit that references this issue on Jul 25, 2025
  8. added a commit that references this issue on May 21, 2026
  9. added a commit that references this issue on May 25, 2026
    3609156
  10. added a commit that references this issue on Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions