Skip to content

Commit

Permalink
Use gts style (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Jun 2, 2021
1 parent c798fca commit ab23cdb
Show file tree
Hide file tree
Showing 41 changed files with 9,153 additions and 8,319 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ jobs:
- run: npm install
- run: npm test

static_analysis:
name: "Static analysis"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with: {node-version: "${{ env.NODE_VERSION }}"}
- run: npm install
- run: npm run lint

dart_sass:
name: Dart Sass
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
3 changes: 0 additions & 3 deletions .prettierrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
}
preset: 'ts-jest',
testEnvironment: 'node',
};
141 changes: 72 additions & 69 deletions lib-js/cli-args.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import path from "path"
import yargs from "yargs/yargs"
import { Argv } from "yargs"
import { Compiler, DartCompiler, ExecutableCompiler } from "./compiler"
import path from 'path';
import yargs from 'yargs/yargs';
import {Argv} from 'yargs';
import {Compiler, DartCompiler, ExecutableCompiler} from './compiler';

export interface CliArgs {
root: string
verbose: boolean
impl: string
compiler: Compiler
interactive: boolean
testDirs: string[]
todoMode?: string
root: string;
verbose: boolean;
impl: string;
compiler: Compiler;
interactive: boolean;
testDirs: string[];
todoMode?: string;
}

const implArgs: Record<string, string[]> = {
"dart-sass": ["--verbose", "--no-unicode", "--no-color"],
libsass: ["--style", "expanded"],
}
'dart-sass': ['--verbose', '--no-unicode', '--no-color'],
libsass: ['--style', 'expanded'],
};

const usageText = `
Usage: ts-node ./sass-spec.ts [options] [spec_directory...]
Expand All @@ -26,7 +26,7 @@ that are named input.scss. It will then run a specified binary and check that
the output matches the expected output.
Make sure the command you provide prints to stdout.
`.trim()
`.trim();

/**
* Parse command line args into options used by the sass-spec runner.
Expand All @@ -39,93 +39,96 @@ export async function parseArgs(
wrap = (t: Argv<{}>) => t
): Promise<CliArgs> {
const argv = wrap(yargs(cliArgs))
.parserConfiguration({
'parse-numbers': false,
})
.usage(usageText)
.example(
"npm run ./sass-spec.js -- spec/basic",
"Run tests only in the spec/basic folder"
'npm run ./sass-spec.js -- spec/basic',
'Run tests only in the spec/basic folder'
)
.option("verbose", {
alias: "v",
description: "Run verbosely",
type: "boolean",
.option('verbose', {
alias: 'v',
description: 'Run verbosely',
type: 'boolean',
})
.option("dart", {
description: "Run Dart Sass, whose repo should be at the given path",
type: "string",
.option('dart', {
description: 'Run Dart Sass, whose repo should be at the given path',
type: 'string',
})
.option("command", {
alias: "c",
description: "Sets a specific binary to run",
type: "string",
.option('command', {
alias: 'c',
description: 'Sets a specific binary to run',
type: 'string',
})
.conflicts("dart", "command")
.check(({ dart, command }) => {
.conflicts('dart', 'command')
.check(({dart, command}) => {
if (!dart && !command) {
throw new Error("Must specify --dart or --command")
throw new Error('Must specify --dart or --command');
} else {
return true
return true;
}
})
.option("cmd-args", {
description: "Pass args to command or Dart Sass",
type: "string",
.option('cmd-args', {
description: 'Pass args to command or Dart Sass',
type: 'string',
})
.option("impl", {
description: "Sets the name of the implementation being tested.",
type: "string",
.option('impl', {
description: 'Sets the name of the implementation being tested.',
type: 'string',
})
.options("run-todo", {
description: "Run any tests marked as todo",
type: "boolean",
.options('run-todo', {
description: 'Run any tests marked as todo',
type: 'boolean',
})
.options("probe-todo", {
description: "Run and report tests marked as todo that unexpectedly pass",
type: "boolean",
.options('probe-todo', {
description: 'Run and report tests marked as todo that unexpectedly pass',
type: 'boolean',
})
.conflicts("run-todo", "probe-todo")
.option("root-path", {
.conflicts('run-todo', 'probe-todo')
.option('root-path', {
description:
"The root path to start searching for tests and test configuration, and the path to pass into --load-path",
type: "string",
default: "spec",
'The root path to start searching for tests and test configuration, and the path to pass into --load-path',
type: 'string',
default: 'spec',
})
.options("interactive", {
.options('interactive', {
description:
"When a test fails, enter into a dialog for how to handle it",
type: "boolean",
'When a test fails, enter into a dialog for how to handle it',
type: 'boolean',
default: false,
}).argv
}).argv;

const root = path.resolve(process.cwd(), argv["root-path"])
const root = path.resolve(process.cwd(), argv['root-path']);

const args: Partial<CliArgs> = {
root,
verbose: argv.verbose,
interactive: argv.interactive,
testDirs: argv._,
todoMode: argv["run-todo"]
? "run"
: argv["probe-todo"]
? "probe"
testDirs: argv._ as string[],
todoMode: argv['run-todo']
? 'run'
: argv['probe-todo']
? 'probe'
: undefined,
}
args.impl = argv.dart ? "dart-sass" : argv.impl!
let cmdArgs = implArgs[args.impl] ?? []
cmdArgs.push(`--load-path=${root}`)
if (argv["cmd-args"]) {
cmdArgs = cmdArgs.concat(argv["cmd-args"].split(" "))
};
args.impl = argv.dart ? 'dart-sass' : argv.impl!;
let cmdArgs = implArgs[args.impl] ?? [];
cmdArgs.push(`--load-path=${root}`);
if (argv['cmd-args']) {
cmdArgs = cmdArgs.concat(argv['cmd-args'].split(' '));
}

if (argv.command) {
args.compiler = new ExecutableCompiler(
path.resolve(process.cwd(), argv.command),
cmdArgs
)
);
}
if (argv.dart) {
const repoPath = path.resolve(process.cwd(), argv.dart)
args.compiler = await DartCompiler.fromRepo(repoPath, cmdArgs)
const repoPath = path.resolve(process.cwd(), argv.dart);
args.compiler = await DartCompiler.fromRepo(repoPath, cmdArgs);
}

return args as CliArgs
return args as CliArgs;
}
Loading

0 comments on commit ab23cdb

Please sign in to comment.