Skip to content

Commit

Permalink
Factor out global chai setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 16, 2023
1 parent aed727c commit d2c10b0
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 195 deletions.
10 changes: 2 additions & 8 deletions test/bin.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import { Index } from '../src/types/IndexType'
import { Version } from '../src/types/Version'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
9 changes: 3 additions & 6 deletions test/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import chai, { expect } from 'chai'
import chaiString from 'chai-string'
import { expect } from 'chai'
import fs from 'fs/promises'
import { rimraf } from 'rimraf'
import ncu from '../src/'
import { CACHE_DELIMITER, resolvedDefaultCacheFile } from '../src/lib/cache'
import { CacheData } from '../src/types/Cacher'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

describe('cache', () => {
it('cache latest versions', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/cli-options.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai from 'chai'
import cliOptions from '../src/cli-options'
import chaiSetup from './helpers/chaiSetup'

chai.should()
chaiSetup()

describe('cli-options', () => {
it('require long and description properties', () => {
Expand Down
11 changes: 4 additions & 7 deletions test/deep.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { expect } from 'chai'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import ncu from '../src/'
import mergeOptions from '../src/lib/mergeOptions'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down Expand Up @@ -220,7 +217,7 @@ describe('mergeOptions', function () {
o1: Record<string, unknown> | null,
o2: Record<string, unknown> | null,
result: Record<string, unknown>,
) => chai.expect(mergeOptions(o1, o2)).to.deep.equal(result)
) => expect(mergeOptions(o1, o2)).to.deep.equal(result)

// trivial cases
eq(null, null, {})
Expand Down
10 changes: 2 additions & 8 deletions test/dep.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

const packageData = JSON.stringify({
dependencies: {
Expand Down
4 changes: 2 additions & 2 deletions test/determinePackageManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai from 'chai'
import determinePackageManager from '../src/lib/determinePackageManager'
import chaiSetup from './helpers/chaiSetup'

chai.should()
chaiSetup()

const isWindows = process.platform === 'win32'

Expand Down
10 changes: 2 additions & 8 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
Expand All @@ -9,13 +6,10 @@ import spawn from 'spawn-please'
import { cliOptionsMap } from '../src/cli-options'
import { chalkInit } from '../src/lib/chalk'
import { PackageManagerName } from '../src/types/PackageManagerName'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')
const doctorTests = path.join(__dirname, 'test-data/doctor')
Expand Down
5 changes: 2 additions & 3 deletions test/enginesNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import chai from 'chai'
import ncu from '../src/'
import { Index } from '../src/types/IndexType'
import { VersionSpec } from '../src/types/VersionSpec'
import chaiSetup from './helpers/chaiSetup'

chai.should()
process.env.NCU_TESTS = 'true'
chaiSetup()

describe('enginesNode', () => {
it("update packages that satisfy the project's engines.node", async () => {
Expand Down
7 changes: 2 additions & 5 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import fs from 'fs/promises'
import path from 'path'
import spawn from 'spawn-please'
import ncu from '../src'
import { Index } from '../src/types/IndexType'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
9 changes: 3 additions & 6 deletions test/filterResults.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import chai, { expect } from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import { expect } from 'chai'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)
chaiSetup()

describe('filterResults', () => {
it('should return only major versions updated', async () => {
Expand Down
7 changes: 2 additions & 5 deletions test/filterVersion.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import path from 'path'
import spawn from 'spawn-please'
import ncu from '../src'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
9 changes: 3 additions & 6 deletions test/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import chai, { expect } from 'chai'
import chaiString from 'chai-string'
import { expect } from 'chai'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
6 changes: 2 additions & 4 deletions test/getAllPackages.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import path from 'path'
import getAllPackages from '../src/lib/getAllPackages'
import { Options } from '../src/types/Options'
import { PackageInfo } from '../src/types/PackageInfo'
import chaiSetup from './helpers/chaiSetup'

chai.should()
chai.use(chaiAsPromised)
chaiSetup()

/** forces path to a posix version (windows-style) */
function asPosixPath(filepath: string): string {
Expand Down
4 changes: 2 additions & 2 deletions test/getCurrentDependencies.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chai from 'chai'
import { SemVer } from 'semver-utils'
import getCurrentDependencies from '../src/lib/getCurrentDependencies'
import { PackageFile } from '../src/types/PackageFile'
import chaiSetup from './helpers/chaiSetup'

chai.should()
chaiSetup()

describe('getCurrentDependencies', () => {
let deps: PackageFile
Expand Down
5 changes: 2 additions & 3 deletions test/getIgnoredUpgrades.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import chai from 'chai'
import getIgnoredUpgrades from '../src/lib/getIgnoredUpgrades'
import chaiSetup from './helpers/chaiSetup'

chai.should()
process.env.NCU_TESTS = 'true'
chaiSetup()

describe('getIgnoredUpgrades', function () {
it('ncu-test-peer-update', async () => {
Expand Down
5 changes: 2 additions & 3 deletions test/getPeerDependenciesFromRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import chai from 'chai'
import { chalkInit } from '../src/lib/chalk'
import getPeerDependenciesFromRegistry from '../src/lib/getPeerDependenciesFromRegistry'
import chaiSetup from './helpers/chaiSetup'

chai.should()
process.env.NCU_TESTS = 'true'
chaiSetup()

describe('getPeerDependenciesFromRegistry', function () {
it('single package', async () => {
Expand Down
5 changes: 2 additions & 3 deletions test/getPreferredWildcard.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import chai from 'chai'
import getPreferredWildcard from '../src/lib/getPreferredWildcard'
import chaiSetup from './helpers/chaiSetup'

const should = chai.should()
process.env.NCU_TESTS = 'true'
const should = chaiSetup()

describe('getPreferredWildcard', () => {
it('identify ^ when it is preferred', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/getRepoUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai from 'chai'
import getRepoUrl from '../src/lib/getRepoUrl'
import chaiSetup from './helpers/chaiSetup'

const should = chai.should()
const should = chaiSetup()

describe('getRepoUrl', () => {
it('return null if package is not installed', async () => {
Expand Down
5 changes: 2 additions & 3 deletions test/github-urls.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import chai from 'chai'
import ncu from '../src'
import chaiSetup from './helpers/chaiSetup'

chai.should()
process.env.NCU_TESTS = 'true'
chaiSetup()

describe('github urls', () => {
it('upgrade github https urls', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/global.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path'
import spawn from 'spawn-please'
import chaiSetup from './helpers/chaiSetup'

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
8 changes: 2 additions & 6 deletions test/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import { GroupFunction } from '../src/types/GroupFunction'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
19 changes: 19 additions & 0 deletions test/helpers/chaiSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'

/** Global chai setup. */
const chaiSetup = () => {
const should = chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)

// do not truncate strings in error messages
chai.config.truncateThreshold = 0

process.env.NCU_TESTS = 'true'

return should
}

export default chaiSetup
10 changes: 2 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiString from 'chai-string'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiAsPromised)
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

describe('run', function () {
it('return jsonUpgraded by default', async () => {
Expand Down
9 changes: 3 additions & 6 deletions test/install.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* eslint-disable no-unused-expressions */
// eslint doesn't like .to.be.false syntax
import chai, { expect } from 'chai'
import chaiString from 'chai-string'
import { expect } from 'chai'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import exists from '../src/lib/exists'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'

chai.should()
chai.use(chaiString)

process.env.NCU_TESTS = 'true'
chaiSetup()

const bin = path.join(__dirname, '../build/src/bin/cli.js')

Expand Down
Loading

0 comments on commit d2c10b0

Please sign in to comment.