Skip to content

Commit

Permalink
test: skip test ability
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 13, 2024
1 parent a55ee1f commit 7d4961d
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 132 deletions.
28 changes: 16 additions & 12 deletions demo/cjs/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

fs = require 'fs'
path = require 'path'
{ exec } = require 'child_process'
fs = require 'node:fs'
path = require 'node:path'
{ spawn } = require 'node:child_process'

dir = path.resolve __dirname, '../lib'
samples = fs.readdirSync dir
Expand All @@ -12,12 +12,16 @@ describe 'Samples', ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
bin = switch ext
when '.js'
'node'
when '.ts'
'ts-node' # Also works with: `node --loader ts-node/esm`
exec "#{bin} #{path.resolve dir, sample}", (err, stdout, stderr) ->
callback err
it "Sample #{sample}", () ->
data = await fs.promises.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['ts-node', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
34 changes: 19 additions & 15 deletions demo/esm/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../lib'
samples = fs.readdirSync dir
samples = await fs.readdir dir

describe 'Samples', ->

Expand All @@ -15,12 +14,17 @@ describe 'Samples', ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
bin = switch ext
when '.js'
'node'
when '.ts'
'node --loader ts-node/esm'
exec "#{bin} #{path.resolve dir, sample}", (err, stdout, stderr) ->
callback err

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
23 changes: 13 additions & 10 deletions demo/issues-cjs/test/samples.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ describe 'Samples', ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
cmd = switch ext
when '.js'
'node'
when '.ts'
'ts-node' # Also works with: `node --loader ts-node/esm`
spawn(cmd, [path.resolve dir, sample])
.on 'close', (code) -> callback(code isnt 0 and new Error 'Failure')
.stdout.on 'data', (->)
it "Sample #{sample}", () ->
data = await fs.promises.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
35 changes: 19 additions & 16 deletions demo/issues-esm/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import fs from 'node:fs';
import path from 'node:path';
import { spawn } from 'node:child_process';
import { dirname } from 'dirname-filename-esm';
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

__dirname = dirname import.meta
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../lib'
samples = fs.readdirSync dir
samples = await fs.readdir dir

describe 'Samples', ->

Expand All @@ -15,13 +14,17 @@ describe 'Samples', ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> callback(code isnt 0 and new Error 'Failure')
.stdout.on 'data', (->)

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
34 changes: 19 additions & 15 deletions demo/ts-esm-node16/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../lib'
samples = fs.readdirSync dir
samples = await fs.readdir dir

describe 'Samples', ->

Expand All @@ -15,12 +14,17 @@ describe 'Samples', ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
bin = switch ext
when '.js'
'node'
when '.ts'
'node --loader ts-node/esm'
exec "#{bin} #{path.resolve dir, sample}", (err, stdout, stderr) ->
callback err

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
37 changes: 25 additions & 12 deletions packages/csv-generate/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@

import each from 'each'
import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../samples'
samples = fs.readdirSync(dir).filter (sample) -> /\.js$/.test sample
samples = await fs.readdir dir

describe 'Samples', ->

each samples, (sample) ->
it "Sample #{sample}", (callback) ->
exec "node #{path.resolve dir, sample}", (err) ->
callback err

samples
.filter (sample) ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
43 changes: 27 additions & 16 deletions packages/csv-parse/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import each from 'each'
import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
dir = path.resolve __dirname, '../samples'
[_, major] = process.version.match(/(\d+)\.\d+\.\d+/)
samples = fs.readdirSync(dir)
.filter (sample) -> ! (major < 16 && sample is 'recipe.promises.js')
.filter (sample) -> /\.js$/.test sample
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../samples'
samples = await fs.readdir dir

describe 'Samples', ->

each samples, (sample) ->
it "Sample #{sample}", (callback) ->
exec "node #{path.resolve dir, sample}", (err) ->
callback err

samples
.filter (sample) -> ! (major < 16 && sample is 'recipe.promises.js')
.filter (sample) ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
37 changes: 25 additions & 12 deletions packages/csv-stringify/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@

import each from 'each'
import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../samples'
samples = fs.readdirSync(dir).filter (sample) -> /\.js$/.test sample
samples = await fs.readdir dir

describe 'Samples', ->

each samples, (sample) ->
it "Sample #{sample}", (callback) ->
exec "node #{path.resolve dir, sample}", (err) ->
callback err

samples
.filter (sample) ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
37 changes: 25 additions & 12 deletions packages/csv/test/samples.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@

import each from 'each'
import fs from 'fs'
import path from 'path'
import { exec } from 'child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import { spawn } from 'node:child_process'

import { fileURLToPath } from 'url'
__dirname = path.dirname fileURLToPath import.meta.url
__dirname = new URL( '.', import.meta.url).pathname
dir = path.resolve __dirname, '../samples'
samples = fs.readdirSync(dir).filter (sample) -> /\.js$/.test sample
samples = await fs.readdir dir

describe 'Samples', ->

each samples, (sample) ->
it "Sample #{sample}", (callback) ->
exec "node #{path.resolve dir, sample}", (err) ->
callback err

samples
.filter (sample) ->
return false unless /\.(js|ts)?$/.test sample
true
.map (sample) ->

it "Sample #{sample}", () ->
data = await fs.readFile path.resolve(dir, sample), 'utf8'
return if /^["|']skip test["|']/.test data
new Promise (resolve, reject) ->
ext = /\.(\w+)?$/.exec(sample)[0]
[cmd, ...args] = switch ext
when '.js'
['node', path.resolve dir, sample]
when '.ts'
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> if code is 0 then resolve() else reject(new Error 'Failure')
.stdout.on 'data', (->)
Loading

0 comments on commit 7d4961d

Please sign in to comment.