Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: run eslint on test dir
  • Loading branch information
lukeed committed Jun 20, 2020
commit 8cf0d7c59ba7d1a5559e5419c764725fcdc9b3b6
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mocha": "8.0.1"
},
"scripts": {
"lint": "eslint src",
"lint": "eslint src test",
"build": "babel --out-dir lib src",
"autotest": "chokidar src test -c 'npm test'",
"test": "mocha -r @babel/register",
Expand Down
38 changes: 19 additions & 19 deletions test/test-cases.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"use strict";
'use strict';

import assert from "assert"
import fs from "fs"
import path from "path"
import FileSystemLoader from "../src/file-system-loader"
import assert from 'assert'
import fs from 'fs'
import path from 'path'
import FileSystemLoader from '../src/file-system-loader'

let normalize = ( str ) => {
return str.replace( /\r\n?/g, "\n" );
return str.replace( /\r\n?/g, '\n' );
}

const pipelines = {
"test-cases": undefined,
"cssi": []
'test-cases': undefined,
'cssi': []
}

Object.keys( pipelines ).forEach( dirname => {
describe( dirname, () => {
let testDir = path.join( __dirname, dirname )
fs.readdirSync( testDir ).forEach( testCase => {
if ( fs.existsSync( path.join( testDir, testCase, "source.css" ) ) ) {
it( "should " + testCase.replace( /-/g, " " ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
if ( fs.existsSync( path.join( testDir, testCase, 'source.css' ) ) ) {
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => {
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
loader.fetch( `${testCase}/source.css`, '/' ).then( tokens => {
assert.equal( loader.finalSource, expected )
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
} ).then( done, done )
Expand All @@ -38,13 +38,13 @@ describe( 'multiple sources', () => {
let testDir = path.join( __dirname, 'test-cases' )
let testCase = 'multiple-sources';
let dirname = 'test-cases';
if ( fs.existsSync( path.join( testDir, testCase, "source1.css" ) ) ) {
it( "should " + testCase.replace( /-/g, " " ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
if ( fs.existsSync( path.join( testDir, testCase, 'source1.css' ) ) ) {
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
loader.fetch( `${testCase}/source1.css`, "/" ).then( tokens1 => {
loader.fetch( `${testCase}/source2.css`, "/" ).then( tokens2 => {
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
loader.fetch( `${testCase}/source1.css`, '/' ).then( tokens1 => {
loader.fetch( `${testCase}/source2.css`, '/' ).then( tokens2 => {
assert.equal( loader.finalSource, expected )
const tokens = Object.assign({}, tokens1, tokens2);
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
Expand Down