Skip to content

Commit

Permalink
Port tests to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Sep 24, 2021
1 parent 8a01a37 commit 1e21a95
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 121 deletions.
11 changes: 5 additions & 6 deletions test/base.js
@@ -1,10 +1,9 @@
'use strict'
const test = require('ava')
const path = require('path')
import test from 'ava'
import path from 'path'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--base --dir works', async (t) => {
const dir = tmp()
Expand Down
9 changes: 4 additions & 5 deletions test/cli.js
@@ -1,9 +1,8 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('works with defaults', async (t) => {
const output = tmp('output.css')
Expand Down
11 changes: 5 additions & 6 deletions test/config.js
@@ -1,11 +1,10 @@
'use strict'
const test = require('ava')
const path = require('path')
import test from 'ava'
import path from 'path'

const ENV = require('./helpers/env.js')
import ENV from './helpers/env.js'

const cli = require('./helpers/cli.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import read from './helpers/read.js'

test('supports common config', async (t) => {
const env = `module.exports = {
Expand Down
11 changes: 5 additions & 6 deletions test/dir.js
@@ -1,10 +1,9 @@
'use strict'
const test = require('ava')
const path = require('path')
import test from 'ava'
import path from 'path'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--dir works', async (t) => {
const dir = tmp()
Expand Down
7 changes: 3 additions & 4 deletions test/error.js
@@ -1,8 +1,7 @@
'use strict'
const test = require('ava')
import test from 'ava'

const tmp = require('./helpers/tmp.js')
const cli = require('./helpers/cli.js')
import tmp from './helpers/tmp.js'
import cli from './helpers/cli.js'

test('multiple input files && --output', (t) => {
return cli(['test/fixtures/*.css', '-o', tmp()]).then(({ error, code }) => {
Expand Down
11 changes: 5 additions & 6 deletions test/ext.js
@@ -1,11 +1,10 @@
'use strict'
const test = require('ava')
import test from 'ava'

const fs = require('fs-extra')
const path = require('path')
import fs from 'fs-extra'
import path from 'path'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'

test('--ext works', async (t) => {
const dir = tmp()
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/_bad-plugin.js
@@ -1,2 +1 @@
'use strict'
throw new Error('This fails')
11 changes: 5 additions & 6 deletions test/glob.js
@@ -1,10 +1,9 @@
'use strict'
const test = require('ava')
const path = require('path')
import test from 'ava'
import path from 'path'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('works with glob patterns', async (t) => {
const output = tmp()
Expand Down
3 changes: 1 addition & 2 deletions test/helpers/clean.js
@@ -1,5 +1,4 @@
'use strict'
const fs = require('fs-extra')
import fs from 'fs-extra'

Promise.all([
fs.emptyDir('./test/fixtures/.tmp/'),
Expand Down
7 changes: 3 additions & 4 deletions test/helpers/cli.js
@@ -1,8 +1,7 @@
'use strict'
const path = require('path')
const { exec } = require('child_process')
import path from 'path'
import { exec } from 'child_process'

module.exports = function (args, cwd) {
export default function (args, cwd) {
return new Promise((resolve) => {
exec(
`node ${path.resolve('index.js')} ${args.join(' ')}`,
Expand Down
13 changes: 6 additions & 7 deletions test/helpers/env.js
@@ -1,11 +1,10 @@
'use strict'
const fs = require('fs-extra')
const path = require('path')
const globby = require('globby')
import fs from 'fs-extra'
import path from 'path'
import globby from 'globby'

const tmp = require('./tmp.js')
import tmp from './tmp.js'

module.exports = function (config, fixtures) {
export default function (config, fixtures) {
fixtures = fixtures || '**/*'
const dir = tmp()

Expand All @@ -15,6 +14,6 @@ module.exports = function (config, fixtures) {
return fs.copy(path.join('test/fixtures', item), path.join(dir, item))
})
}),
fs.outputFile(path.join(dir, 'postcss.config.js'), config),
fs.outputFile(path.join(dir, 'postcss.config.cjs'), config),
]).then(() => dir)
}
5 changes: 2 additions & 3 deletions test/helpers/read.js
@@ -1,7 +1,6 @@
'use strict'
const { readFile } = require('fs-extra')
import { readFile } from 'fs/promises'

module.exports = function (path) {
export default function (path) {
return readFile(path, 'utf8').then(
(content) => content.replace(/\r\n/g, '\n') // normalize line endings on Windows
)
Expand Down
7 changes: 3 additions & 4 deletions test/helpers/tmp.js
@@ -1,8 +1,7 @@
'use strict'
const path = require('path')
const { v4: uuid } = require('uuid')
import path from 'path'
import { v4 as uuid } from 'uuid'

module.exports = function (ext) {
export default function (ext) {
ext = ext || ''

return path.join('test/fixtures/.tmp', uuid(), ext)
Expand Down
11 changes: 5 additions & 6 deletions test/map.js
@@ -1,10 +1,9 @@
'use strict'
const test = require('ava')
const fs = require('fs-extra')
import test from 'ava'
import fs from 'fs-extra'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('inline maps are generated by default', async (t) => {
const output = tmp('output.css')
Expand Down
5 changes: 2 additions & 3 deletions test/misc.js
@@ -1,7 +1,6 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
import cli from './helpers/cli.js'

test('--help', async (t) => {
const help = await cli(['--help'])
Expand Down
9 changes: 4 additions & 5 deletions test/parser.js
@@ -1,9 +1,8 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--parser works', async (t) => {
const output = tmp('output.css')
Expand Down
13 changes: 6 additions & 7 deletions test/replace.js
@@ -1,12 +1,11 @@
'use strict'
const test = require('ava')
import test from 'ava'

const fs = require('fs-extra')
const path = require('path')
import fs from 'fs-extra'
import path from 'path'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--replace works', async (t) => {
const dir = tmp()
Expand Down
13 changes: 6 additions & 7 deletions test/stdin.js
@@ -1,12 +1,11 @@
'use strict'
const test = require('ava')
import test from 'ava'

const fs = require('fs-extra')
const path = require('path')
const { exec } = require('child_process')
import fs from 'fs-extra'
import path from 'path'
import { exec } from 'child_process'

const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test.cb('reads from stdin', (t) => {
const output = tmp('output.css')
Expand Down
11 changes: 5 additions & 6 deletions test/stdout.js
@@ -1,11 +1,10 @@
'use strict'
const test = require('ava')
import test from 'ava'

const fs = require('fs-extra')
const path = require('path')
const { exec } = require('child_process')
import fs from 'fs-extra'
import path from 'path'
import { exec } from 'child_process'

const read = require('./helpers/read.js')
import read from './helpers/read.js'

test.cb('writes to stdout', (t) => {
const cp = exec(
Expand Down
9 changes: 4 additions & 5 deletions test/stringifier.js
@@ -1,9 +1,8 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--stringifier works', async (t) => {
const output = tmp('output.sss')
Expand Down
9 changes: 4 additions & 5 deletions test/syntax.js
@@ -1,9 +1,8 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--syntax works', async (t) => {
const output = tmp('output.sss')
Expand Down
9 changes: 4 additions & 5 deletions test/use.js
@@ -1,9 +1,8 @@
'use strict'
const test = require('ava')
import test from 'ava'

const cli = require('./helpers/cli.js')
const tmp = require('./helpers/tmp.js')
const read = require('./helpers/read.js')
import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

test('--use works', async (t) => {
const output = tmp('i.css')
Expand Down
23 changes: 11 additions & 12 deletions test/watch.js
@@ -1,14 +1,13 @@
'use strict'
const test = require('ava')
import test from 'ava'

const fs = require('fs-extra')
const path = require('path')
const { exec, spawn } = require('child_process')
const chokidar = require('chokidar')
import fs from 'fs-extra'
import path from 'path'
import { exec, spawn } from 'child_process'
import chokidar from 'chokidar'

const ENV = require('./helpers/env.js')
const read = require('./helpers/read.js')
const tmp = require('./helpers/tmp.js')
import ENV from './helpers/env.js'
import read from './helpers/read.js'
import tmp from './helpers/tmp.js'

// XXX: All the tests in this file are skipped on the CI; too flacky there
const testCb = process.env.CI ? test.cb.skip : test.cb
Expand Down Expand Up @@ -224,7 +223,7 @@ testCb('--watch watches dependencies', (t) => {

ENV('', ['s.css', 'a.css', 'b.css']).then((dir) => {
fs.writeFile(
path.join(dir, 'postcss.config.js'),
path.join(dir, 'postcss.config.cjs'),
`
const fs = require('fs')
module.exports = {
Expand Down Expand Up @@ -318,7 +317,7 @@ testCb('--watch watches directory dependencies', (t) => {
ENV('', ['s.css', 'base/level-1/b.css', 'base/level-1/level-2/a.css']).then(
(dir) => {
fs.writeFile(
path.join(dir, 'postcss.config.js'),
path.join(dir, 'postcss.config.cjs'),
`
const fs = require('fs')
module.exports = {
Expand Down Expand Up @@ -427,7 +426,7 @@ testCb(
'base/level-1/level-2/unrelated.md',
]).then((dir) => {
fs.writeFile(
path.join(dir, 'postcss.config.js'),
path.join(dir, 'postcss.config.cjs'),
`
const fs = require('fs')
module.exports = {
Expand Down

0 comments on commit 1e21a95

Please sign in to comment.