Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Undo integration of @atom/notify #19352

Merged
merged 4 commits into from May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,6 @@
"license": "MIT",
"electronVersion": "2.0.18",
"dependencies": {
"@atom/notify": "1.3.3",
"@atom/nsfw": "1.0.22",
"@atom/source-map-support": "^0.3.4",
"@atom/watcher": "1.3.1",
Expand Down
1 change: 0 additions & 1 deletion script/lib/generate-startup-snapshot.js
Expand Up @@ -69,7 +69,6 @@ module.exports = function (packagedAppPath) {
requiredModuleRelativePath === path.join('..', 'node_modules', 'yauzl', 'index.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'winreg', 'lib', 'registry.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', '@atom', 'fuzzy-native', 'lib', 'main.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', '@atom', 'notify', 'lib', 'bin-path.js') ||
// The startup-time script is used by both the renderer and the main process and having it in the
// snapshot causes issues.
requiredModuleRelativePath === path.join('..', 'src', 'startup-time.js')
Expand Down
1 change: 0 additions & 1 deletion script/lib/package-application.js
Expand Up @@ -112,7 +112,6 @@ function buildAsarUnpackGlobExpression () {
path.join('**', 'node_modules', 'dugite', 'git', '**'),
path.join('**', 'node_modules', 'github', 'bin', '**'),
path.join('**', 'node_modules', 'vscode-ripgrep', 'bin', '**'),
path.join('**', 'node_modules', '@atom', 'notify', 'bin', '**'),
path.join('**', 'resources', 'atom.png')
]

Expand Down
1 change: 0 additions & 1 deletion script/test
Expand Up @@ -48,7 +48,6 @@ const resourcePath = CONFIG.repositoryRootPath
let executablePath
if (process.platform === 'darwin') {
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '*.app'))
assert(executablePaths.length > 0, `No application found in ${CONFIG.buildOutputPath} to run tests against`)
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
executablePath = path.join(executablePaths[0], 'Contents', 'MacOS', path.basename(executablePaths[0], '.app'))
} else if (process.platform === 'linux') {
Expand Down
5 changes: 1 addition & 4 deletions script/vsts/platforms/windows.yml
Expand Up @@ -78,10 +78,7 @@ jobs:
IS_SIGNED_ZIP_BRANCH: $(IsSignedZipBranch)
displayName: Build Atom

- powershell: |
# Normalize %TEMP% as a long (non 8.3) path to avoid assertion failures comparing paths in temp folders
$env:TEMP = (Get-Item -LiteralPath $env:TEMP).FullName
node script\vsts\windows-run.js script\test.cmd
- script: node script\vsts\windows-run.js script\test.cmd
env:
CI: true
CI_PROVIDER: VSTS
Expand Down
217 changes: 103 additions & 114 deletions spec/path-watcher-spec.js
Expand Up @@ -6,7 +6,7 @@ import path from 'path'
import { promisify } from 'util'

import { CompositeDisposable } from 'event-kit'
import { PathWatcherManager } from '../src/path-watcher'
import { watchPath, stopAllWatchers } from '../src/path-watcher'

temp.track()

Expand All @@ -17,7 +17,7 @@ const realpath = promisify(fs.realpath)

const tempMkdir = promisify(temp.mkdir)

describe('PathWatcherManager', function () {
describe('watchPath', function () {
let subs

beforeEach(function () {
Expand All @@ -26,6 +26,7 @@ describe('PathWatcherManager', function () {

afterEach(async function () {
subs.dispose()
await stopAllWatchers()
})

function waitForChanges (watcher, ...fileNames) {
Expand All @@ -50,136 +51,124 @@ describe('PathWatcherManager', function () {
})
}

describe('in "native" mode', () => {
let manager
describe('watchPath()', function () {
it('resolves the returned promise when the watcher begins listening', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')

beforeEach(function () {
manager = new PathWatcherManager('native')
const watcher = await watchPath(rootDir, {}, () => {})
expect(watcher.constructor.name).toBe('PathWatcher')
})

afterEach(async function () {
await manager.stopAllWatchers()
})

describe('watchPath()', function () {
it('resolves the returned promise when the watcher begins listening', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')

const watcher = await manager.watchPath(rootDir, {}, () => {})
expect(watcher.constructor.name).toBe('PathWatcher')
})
it('reuses an existing native watcher and resolves getStartPromise immediately if attached to a running watcher', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')

it('reuses an existing native watcher and resolves getStartPromise immediately if attached to a running watcher', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')
const watcher0 = await watchPath(rootDir, {}, () => {})
const watcher1 = await watchPath(rootDir, {}, () => {})

const watcher0 = await manager.watchPath(rootDir, {}, () => {})
const watcher1 = await manager.watchPath(rootDir, {}, () => {})

expect(watcher0.native).toBe(watcher1.native)
})
expect(watcher0.native).toBe(watcher1.native)
})

it("reuses existing native watchers even while they're still starting", async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')
it("reuses existing native watchers even while they're still starting", async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')

const [watcher0, watcher1] = await Promise.all([
manager.watchPath(rootDir, {}, () => {}),
manager.watchPath(rootDir, {}, () => {})
])
expect(watcher0.native).toBe(watcher1.native)
})
const [watcher0, watcher1] = await Promise.all([
watchPath(rootDir, {}, () => {}),
watchPath(rootDir, {}, () => {})
])
expect(watcher0.native).toBe(watcher1.native)
})

it("doesn't attach new watchers to a native watcher that's stopping", async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')
it("doesn't attach new watchers to a native watcher that's stopping", async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-')

const watcher0 = await manager.watchPath(rootDir, {}, () => {})
const native0 = watcher0.native
const watcher0 = await watchPath(rootDir, {}, () => {})
const native0 = watcher0.native

watcher0.dispose()
const watcher1 = await manager.watchPath(rootDir, {}, () => {})
watcher0.dispose()
const watcher1 = await watchPath(rootDir, {}, () => {})

expect(watcher1.native).not.toBe(native0)
})
expect(watcher1.native).not.toBe(native0)
})

it('reuses an existing native watcher on a parent directory and filters events', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-').then(realpath)
const rootFile = path.join(rootDir, 'rootfile.txt')
const subDir = path.join(rootDir, 'subdir')
const subFile = path.join(subDir, 'subfile.txt')
it('reuses an existing native watcher on a parent directory and filters events', async function () {
const rootDir = await tempMkdir('atom-fsmanager-test-').then(realpath)
const rootFile = path.join(rootDir, 'rootfile.txt')
const subDir = path.join(rootDir, 'subdir')
const subFile = path.join(subDir, 'subfile.txt')

await mkdir(subDir)
await mkdir(subDir)

// Keep the watchers alive with an undisposed subscription
const rootWatcher = await manager.watchPath(rootDir, {}, () => {})
const childWatcher = await manager.watchPath(subDir, {}, () => {})
// Keep the watchers alive with an undisposed subscription
const rootWatcher = await watchPath(rootDir, {}, () => {})
const childWatcher = await watchPath(subDir, {}, () => {})

expect(rootWatcher.native).toBe(childWatcher.native)
expect(rootWatcher.native.isRunning()).toBe(true)
expect(rootWatcher.native).toBe(childWatcher.native)
expect(rootWatcher.native.isRunning()).toBe(true)

const firstChanges = Promise.all([
waitForChanges(rootWatcher, subFile),
waitForChanges(childWatcher, subFile)
])
await writeFile(subFile, 'subfile\n', { encoding: 'utf8' })
await firstChanges
const firstChanges = Promise.all([
waitForChanges(rootWatcher, subFile),
waitForChanges(childWatcher, subFile)
])
await writeFile(subFile, 'subfile\n', { encoding: 'utf8' })
await firstChanges

const nextRootEvent = waitForChanges(rootWatcher, rootFile)
await writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' })
await nextRootEvent
})
const nextRootEvent = waitForChanges(rootWatcher, rootFile)
await writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' })
await nextRootEvent
})

it('adopts existing child watchers and filters events appropriately to them', async function () {
const parentDir = await tempMkdir('atom-fsmanager-test-')
.then(realpath)

// Create the directory tree
const rootFile = path.join(parentDir, 'rootfile.txt')
const subDir0 = path.join(parentDir, 'subdir0')
const subFile0 = path.join(subDir0, 'subfile0.txt')
const subDir1 = path.join(parentDir, 'subdir1')
const subFile1 = path.join(subDir1, 'subfile1.txt')

await mkdir(subDir0)
await mkdir(subDir1)
await Promise.all([
writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' }),
writeFile(subFile0, 'subfile 0\n', { encoding: 'utf8' }),
writeFile(subFile1, 'subfile 1\n', { encoding: 'utf8' })
])

// Begin the child watchers and keep them alive
const subWatcher0 = await manager.watchPath(subDir0, {}, () => {})
const subWatcherChanges0 = waitForChanges(subWatcher0, subFile0)

const subWatcher1 = await manager.watchPath(subDir1, {}, () => {})
const subWatcherChanges1 = waitForChanges(subWatcher1, subFile1)

expect(subWatcher0.native).not.toBe(subWatcher1.native)

// Create the parent watcher
const parentWatcher = await manager.watchPath(parentDir, {}, () => {})
const parentWatcherChanges = waitForChanges(
parentWatcher,
rootFile,
subFile0,
subFile1
)

expect(subWatcher0.native).toBe(parentWatcher.native)
expect(subWatcher1.native).toBe(parentWatcher.native)

// Ensure events are filtered correctly
await Promise.all([
appendFile(rootFile, 'change\n', { encoding: 'utf8' }),
appendFile(subFile0, 'change\n', { encoding: 'utf8' }),
appendFile(subFile1, 'change\n', { encoding: 'utf8' })
])

await Promise.all([
subWatcherChanges0,
subWatcherChanges1,
parentWatcherChanges
])
})
it('adopts existing child watchers and filters events appropriately to them', async function () {
const parentDir = await tempMkdir('atom-fsmanager-test-')
.then(realpath)

// Create the directory tree
const rootFile = path.join(parentDir, 'rootfile.txt')
const subDir0 = path.join(parentDir, 'subdir0')
const subFile0 = path.join(subDir0, 'subfile0.txt')
const subDir1 = path.join(parentDir, 'subdir1')
const subFile1 = path.join(subDir1, 'subfile1.txt')

await mkdir(subDir0)
await mkdir(subDir1)
await Promise.all([
writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' }),
writeFile(subFile0, 'subfile 0\n', { encoding: 'utf8' }),
writeFile(subFile1, 'subfile 1\n', { encoding: 'utf8' })
])

// Begin the child watchers and keep them alive
const subWatcher0 = await watchPath(subDir0, {}, () => {})
const subWatcherChanges0 = waitForChanges(subWatcher0, subFile0)

const subWatcher1 = await watchPath(subDir1, {}, () => {})
const subWatcherChanges1 = waitForChanges(subWatcher1, subFile1)

expect(subWatcher0.native).not.toBe(subWatcher1.native)

// Create the parent watcher
const parentWatcher = await watchPath(parentDir, {}, () => {})
const parentWatcherChanges = waitForChanges(
parentWatcher,
rootFile,
subFile0,
subFile1
)

expect(subWatcher0.native).toBe(parentWatcher.native)
expect(subWatcher1.native).toBe(parentWatcher.native)

// Ensure events are filtered correctly
await Promise.all([
appendFile(rootFile, 'change\n', { encoding: 'utf8' }),
appendFile(subFile0, 'change\n', { encoding: 'utf8' }),
appendFile(subFile1, 'change\n', { encoding: 'utf8' })
])

await Promise.all([
subWatcherChanges0,
subWatcherChanges1,
parentWatcherChanges
])
})
})
})